Classic ASP MSXML2.ServerHTTP Post - Youtube Api - asp-classic

I am trying to build an application where i can upload files to youtube.
I have gotten OAuth working, and Youtube is returning a session!
The problem i am having is, youtube requires i make an XMLHTTP POST to get a url where i can upload through my web page.
I have no idea how to make an XMLHTTP Post with the extra parameters youtube requires.
They have code samples in PHP and .net both of which i dont understand yet :(
This is where i am stuck:
http://code.google.com/apis/youtube/2.0/developers_guide_protocol_browser_based_uploading.html#Sending_a_Browser_Upload_API_Request
I dont know how to Format an xml http command to have all those variables youtube wants.
Please help...
here is what they want..
POST /action/GetUploadToken HTTP/1.1
Host: gdata.youtube.com
Authorization: AuthSub token="DXAA...sdb8"
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 1941255
Content-Type: application/atom+xml; charset=UTF-8
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Bad Wedding Toast</media:title>
<media:description type="plain">
I gave a bad toast at my friend's wedding.
</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>toast, wedding</media:keywords>
</media:group>
</entry>
Here is the code i have now:
I think i need the Headers?
When i post it i get a response of not authorized.
I also tried to create an old html and try that but it does not work...
Have no idea how those paramenters are sent:
Here is what i got
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
URLString = "http://gdata.youtube.com/action/GetUploadToken"
SendString = ""
SendString = SendString & "Authorization: AuthSub token=" & token
xmlHttp.open "POST", URLString & "?" & SendString
xmlHttp.setRequestHeader "Host:", "gdata.youtube.com"
xmlHttp.setRequestHeader "Authorization: AuthSub token=", token
xmlHttp.setRequestHeader "GData-Version:", "2"
xmlHttp.setRequestHeader "Content-Length:", "<content_length>"
xmlHttp.setRequestHeader "Content-Type", "application/atom+xml; charset=UTF-"
xmlHttp.send SendString
If xmlHttp.Status >= 400 And xmlHttp.Status <= 599 Then
Response.Write "<BR><BR><BR>Error Occured: " & xmlHttp.statusText
Else
' ReturnData = Replace(xmlHttp.responseText, "&", ",")
Response.Write "<BR><BR><BR>WENT GOOD?<BR>" & xmlHttp.responseText
End If

First, setRequestHeader doesn't take a colon. It should just be
xmlHttp.setRequestHeader "Host", "gdata.youtube.com"
xmlHttp.setRequestHeader "Authorization", "AuthSub token=" & token
xmlHttp.setRequestHeader "GData-Version", "2"
xmlHttp.setRequestHeader "Content-Length", "<content_length>" <-- THIS IS IMPORTANT!
xmlHttp.setRequestHeader "Content-Type", "application/atom+xml; charset=UTF-8"
Next, are you sending the correct content-length? This NEEDS to be accurate.
I assume the missing "8" from your Content-Type header at the end was a typo.
Finally, you NEED to install Fiddler right away and make your life simpler.

Related

Twitter API bearer token request returns forbidden

Simple pull of search tweets needed an I'm getting stuck trying to obtain a bearer token via a classic ASP post.
The server is responding with 403 Unable to verify your credentials
I'm obviously fluid on ASP server side form post so any suggestions would be appreciated. Thanks.
Dim consumerKey,consumerSecret,myCstr
consumerKey = "abc..."
consumerSecret = "123..."
myCstr = base64_encode(consumerKey & ":" & consumerSecret)
myAuth = "Basic "&myCstr
Dim xmlhttp
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST","https://api.twitter.com/oauth2/token",false
xmlhttp.setRequestHeader "User-Agent","HTTP/1.1"
xmlhttp.setRequestHeader "Authorization", myAuth
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"
xmlhttp.send "grant_type=client_credentials"
I resolved it... I needed two equal signs at the end of the end of the base64 string.
That wasn't really very clear in the twitter API docs.

404 error returned from valid URL from Amazon Route 53

I am trying to use Amazon's Route 53 server API from Classic ASP but when I post the request I get back HTTP 404 Not Found error even though the URL sent is valid if I paste it into a browser. Is Classic ASP not capable of calling Route 53 or is there an error in my code?
Dim linebreak, gmt, timestamp, urlparams, amazonserver, stringtosign, signature, signedURL, sha256
const versionDate="2009-07-01"
amazonserver="https://route53.amazonaws.com/2012-02-29/xxxxxxxxxx"
linebreak=chr(13)
const secretkey="my secret key"
gmt=DateAdd("H", 0, Now)
timestamp = return_RFC822_Date(Now(), "GMT")
set sha256=GetObject("script:"&Server.MapPath("sha256.wsc"))
stringtosign = timestamp
signature=sha256.b64_hmac_sha256(secretkey, stringtosign)
header = "AWS3-HTTPS AWSAccessKeyId=ky access id,Algorithm=HMANSHA256,Signature="&signature
Set sha256=nothing
signedURL=amazonserver&"/onca/xml?"&urlparams&"&Signature="&Server.URLEncode(signature)
response.write signedURL
Set xmlHttp = Server.Createobject("Microsoft.XMLHTTP")
xmlHttp.Open "POST", signedUrl, False
response.write strURL&"<br>"
xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
xmlHttp.setRequestHeader "Host", "route53.amazonaws.com"
xmlHttp.setRequestHeader "content-type", "text/plain"
xmlHttp.setRequestHeader "X-Amzn-Authorization", signature
xmlHttp.Send()
if xmlHttp.Status >= 400 And xmlHttp.Status <= 599 Then
response.write "Error Occurred : " & xmlHttp.Status & " - " & xmlHttp.statusText
else
getXML = xmlHttp.responseText
end if
xmlHttp.abort()
set xmlHttp = Nothing

Pingdom REST API from Classic ASP

I would like to use the Pingdom REST API from Classic ASP, but the following code:-
' setup the URL
baseUrl = "https://api.pingdom.com/api/2.0/checks"
' setup the request and authorization
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET", baseUrl, False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "userpwd", "aaaaaaaaaaaaaaaaaaaaaaa:bbbbbbbbbbb"
http.setRequestHeader "App-Key", "ccccccccccccccccccccccccccccccc"
' send the HTTP data
http.send
gives me the error:-
{"error":{"statuscode":401,"statusdesc":"Unauthorized","errormessage":"User credentials missing"}}
so my authentication isnt being passed correctly, and it looks like it should NOT be passed in the requestheader, but I'm not sure how it should be done.
Thanks
Thanks for Alex K. and for the benefit of others, the correct syntax is:-
' setup the URL
baseUrl = "https://api.pingdom.com/api/2.0/checks"
Response.Write fullUrl
' setup the request and authorization
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET", baseUrl, False, "emailaddress", "password"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "App-Key", "keykeykeykeykeykeykeykeykeykey"
' send the HTTP data
http.send
:-)
https://api.pingdom.com/api/2.0/checks is using Basic Authentication so you need to pass your credentials in the .open call.

How create server side multiple request?

I am working with 3 xml's,
i wand to send my 3 xml request to different http's in same time, How it possible?
I using classic asp(VBSCRIPT), below is my code now i use.
Below code is working fine.. But the problem is to take more time to send and recive xml (because it send in different time)
<%
' xml 1
pXML=Server.URLencode(XML_REQUEST_ONE)
set xmlhttp = server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "post", servletURLH01B, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "xml_request=" &pXML
XMLresult_ONE= xmlhttp.responsexml.xml
Set xd= Server.CreateObject ("Microsoft.XMLDOM")
xd.async = "false"
xd.loadXML(XMLresult_ONE)
' xml 2
pXML=Server.URLencode(XML_REQUEST_TWO)
set xmlhttp = server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "post", servletURLH01B, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "xml_request=" &pXML
XMLresult_TWO= xmlhttp.responsexml.xml
Set xd= Server.CreateObject ("Microsoft.XMLDOM")
xd.async = "false"
xd.loadXML(XMLresult_TWO)
' xml 3
pXML=Server.URLencode(XML_REQUEST_THREE)
set xmlhttp = server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "post", servletURLH01B, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "xml_request=" &pXML
XMLresult_THREE= xmlhttp.responsexml.xml
Set xd= Server.CreateObject ("Microsoft.XMLDOM")
xd.async = "false"
xd.loadXML(XMLresult_THREE)
%>
Is it possible to send request and recive response in same time?
hoping ur support
Alex
I'm not sure what you are asking for...
it is impossible to 'send request and recive response in same time'
this is generally due to network latency. Each request over a network is delayed by the physical limitations of the speed of electricity (and server/network loads etc)
BUT i'm really not sure that this is what you are asking.
Do you want to be able to send all three requests simultaneously? and then wait for each response?

Encoding "<" and ">" while sending XML via HTTP Post

I am sending an XML content via HTTP Post from Access VBA to Web Methods, using XMLHTTP object in MSXML. Here is the Code.
Dim objXmlHttp As Object
Set objXmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
objXmlHttp.Open "POST", webServicePath, False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Dim Response As String
objXmlHttp.send wrt.output
'OK status
If objXmlHttp.Status = 200 Then
Response = objXmlHttp.responseText
End If
Set objXmlHttp = Nothing
I am getting the XML with "&lt" and "&gt" instead of < and >.
If I try to do URL encoding, everything is received as ASCII text in the Recipient side.
Can you please guide what I need to do to get the valid XML format.
You need to set the content-type correctly, try this instead:
objXmlHttp.setRequestHeader "Content-Type", "text/xml; charset=""utf-8"""

Resources