Must supply a valid HTTP Basic Authorization header - Classic ASP

This is my code so far, i'm new.

Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
XMLHTTP.Open "POST", "{listid}.{json}", False, "", ""
xmlHTTP.setRequestHeader "Content-Type", "text/xml"
XMLHTTP.setRequestHeader "Authorization", "Basic {APIKey}:{dummypassword}")
xmlHTTP.send "<Client><CompanyName>MyCompany</CompanyName><ContactName>John</ContactName><EmailAddress></EmailAddress><Country>Australia</Country><TimeZone>(GMT+10:00) Canberra, Melbourne, Sydney</TimeZone></Client>"

response.write xmlhttp.responseText

Must supply a valid HTTP Basic Authorization header

Obviously i don't really know what i'm doing.

I read the adding subscriber page here

And it says to post to{listid}.{xml|json}

So do i change that to (2234KJ is my list id for example purposes)

And what should be in the basic authorization code?

For example my api key is GH12345

XMLHTTP.setRequestHeader "Authorization", "Basic GH12345:testpass"


jamesd jamesd, 5 years ago

Yes, you should be posting to if your list id is 2234KJ.

Please see this example of how you do basic HTTP authentication.

You will need to make sure you base64 encode the content of the Authorization header, so the header will end up looking something like:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

rather than:

Authorization: Basic "username:password"

The content of the body of the request in your first code sample looks incorrect for the route you are using. You probably want something more similar to:

  <Name>New Subscriber</Name>
mrfusion, 5 years ago

Thanks! I think i'm getting on track but have a new error.

Failed to deserialize your request. Please check the documentation and try again. Fields in error: subscriber

This is my code now

Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")

Dim apikey
Dim pass
''api key is 0000G as an example

XMLHTTP.Open "POST", "", false
xmlHTTP.setRequestHeader "Content-Type", "text/xml"
XMLHTTP.setRequestHeader "Authorization", "Basic " & Base64Encode(apikey & ":" & pass) 
xmlHTTP.send "<Subscriber><EmailAddress></EmailAddress><Name>FrederickVonGoobenstein</Name><CustomFields><FirstName></FirstName><LastName></LastName><State></State><Suburb></Suburb></CustomFields><Resubscribe>true</Resubscribe></Subscriber>"

response.write xmlhttp.responseText

Gives the deserialize error.

mrfusion, 5 years ago

Ok don't worry, that code above did work. Woo :)

I had a typo on the <Resubscribe> tag.

So there you go future classic asp integrators. (you will have to grab a custom base64 function, many are on the web i used the below one)

Function Base64Encode(inData)
'2001 Antonin Foller, Motobit Software,
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim cOut, sOut, I
'For each group of 3 bytes
For I = 1 To Len(inData) Step 3
Dim nGroup, pOut, sGroup
'Create one long from this 3 bytes.
nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
&H100 * MyASC(Mid(inData, I + 1, 1)) + MyASC(Mid(inData, I + 2, 1))
'Oct splits the long To 8 groups with 3 bits
nGroup = Oct(nGroup)
'Add leading zeros
nGroup = String(8 - Len(nGroup), "0") & nGroup
'Convert To base64
pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)
'Add the part To OutPut string
sOut = sOut + pOut
'Add a new line For Each 76 chars In dest (76*3/4 = 57)
'If (I + 2) Mod 57 = 0 Then sOut = sOut + vbCrLf
Select Case Len(inData) Mod 3
Case 1: '8 bit final
sOut = Left(sOut, Len(sOut) - 2) + "=="
Case 2: '16 bit final
sOut = Left(sOut, Len(sOut) - 1) + "="
End Select
Base64Encode = sOut
End Function
Function MyASC(OneChar)
If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
End Function
SteVader SteVader, 5 years ago

THANK YOU mrfusion! That snippet just saved me a whole heap of pain.

winstongel, 1 year ago

Check here.....Difference between Authorization and Authentication


SiburCrerb, 3 days ago

<a href=>сильный приворот на любовь мужчины</a>
<a href=>заговор на булавку от сглаза</a>
<a href=>как избавиться от приворота самостоятельно</a>
<a href=>заговоры ванги</a>
<a href=>приворот на вещь</a>
<a href=>заговор на свечу на деньги</a>
<a href=>заговор на соль</a>
<a href=>заговор сильный на выигрыш в лотерею</a>
<a href=>заговор на здоровье в рождество</a>
<a href=>заговор на благополучие</a>

заговор на подарок
заговор от тараканов
приворот на свечах
заговоры в пятницу 13
заговор на привлечение денег
обряды на рождество для привлечения любви
сексуальный приворот женатого
скайрим заговор изгоев
заговор чтобы парень позвонил
заговор от головной боли

SiburCrerb, 2 days ago

<a href=>заговор чтобы присниться любимому</a>
<a href=>приворот на любовь мужчины</a>
<a href=>заговор тухачевского</a>
<a href=>заговор на похудения убрать жир</a>
<a href=>как избавиться от приворота самостоятельно</a>
<a href=>приворот на месячную кровь последствия</a>
<a href=>рождественские обряды на любовь</a>
<a href=>приворот на рождество кто делал отзывы</a>
<a href=>приворот оплата по результату</a>
<a href=>черная магия заговоры</a>

приворот девушки по фото
заговор на счастье
самый сильный приворот
заговоры в новогоднюю ночь
заговор на луну
приворот по фото отзывы кто делал
ложка загребушка сувенир для денег заговор отзывы
приворот в домашних условиях кто делал отзывы
заговор на сигарету
порча на смерть признаки и как снять

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free