NetTalk Central

Author Topic: I need to modify the header before posting  (Read 1912 times)

rayrip

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
I need to modify the header before posting
« on: August 31, 2021, 06:29:30 PM »
I have to pass a single api key during the post. I am posting some json to a website and I'm actually getting the data back, which are errors that say it's unauthorized because I'm not passing the api key. I need to pass the api key (a 32 character string) in a header. I tried using this:
authString=apikey;authStringLength=len(clip(authString))
  Postnet.Authorization = 'Basic ' & NetBase64Encode(clip(authString),authStringLength)

and that didn't work. Tried Postnet.Authorization = Postnet.CreateAuthorizationString('',clip(apikey),Net:WebBasicAuthentication,true) and a couple of variations and that didn't work... which I didn't expect it to because it wants a username and password and that doesn't exist.

Hints?

Thanks,
Ray


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: I need to modify the header before posting
« Reply #1 on: September 01, 2021, 05:26:21 AM »
Hi Ray,

I think it'd be helpful if you have more details about specifically what you need in the header.
There are any number of things tat _could_ be in play here, so it's helpful if you know the specifics of what you are actually looking for.

Cheers
Bruce



rayrip

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: I need to modify the header before posting
« Reply #2 on: September 01, 2021, 08:34:49 AM »
I just need to put in the api key which is a string of 32 characters. I do not need to pass a username or password. This api key string is so the server knows who I am. It's for credit card processing. I'm posting and getting data back so everything is working, except I get an unauthorized error back because I didn't pass the api key. The cc company says I need to pass it in the header.

Alberto

  • Hero Member
  • *****
  • Posts: 1844
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: I need to modify the header before posting
« Reply #3 on: September 01, 2021, 12:06:46 PM »
Im sure you got a curl example from the cc company, post it here and we will try to conbert it to NT
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: I need to modify the header before posting
« Reply #4 on: September 02, 2021, 08:06:47 PM »
Hi Ray,

An HTTP header contains a list of name: value pairs. This looks something like this;

POST /updatecustomers HTTP/1.1
Host: 127.0.0.1:88
Connection: keep-alive
Content-Length: 2332
Accept: */*
DNT: 1

And so on.

So when someone says "put it in the header", it's helpful to know which header they are talking about. From your post you imply  it might be the Authorization header. For example;

Authorization: ABCD

To do that is trivial. Simply set

Postnet.Authorization = 'ABCD'

That said the Authorization header is often (correctly) used in a more formal way. For example;

Postnet.Authorization = 'Basic ' & whatever
or
Postnet.Authorization = 'Bearer ' & whatever
or Digest, or NTLM or something else.

The Whatever part is then encoded depending on the form - Basic has a specific encoding, Digest has another and so on.

Hence the question about specifics. We basically need more than "just include in the header" in order to answer your question. An example of the header, or a Curl example would be sufficient to more accurately answer your question.

cheers
Bruce



osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Re: I need to modify the header before posting
« Reply #5 on: September 03, 2021, 05:05:02 AM »
Bruce the NTLM Authentication is working with NT?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: I need to modify the header before posting
« Reply #6 on: September 05, 2021, 10:54:17 PM »
no

rayrip

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: I need to modify the header before posting
« Reply #7 on: September 10, 2021, 03:34:43 PM »
Got it working... the CC vendor gave me the correct string.. it's an api key so
Postnet.SetAllHeadersDefault() 
Postnet.HeaderOnly = 0
Postnet.CustomHeader = 'api-key:' & clip(clearent_key)

I have a function called post_to_url that had to be rewritten for some stuff that capesoft changed. I can use it for posting almost anything now. Anyway, the api-key: did the trick.