Jump to content

http post with header for oauth


Recommended Posts

I've been trying all day to get a "request token" from the dropbox rest-api.

Basically I'm trying to perform step 1 at https://www.dropbox.com/developers/blog/20/using-oauth-in-plaintext-mode:

 

" 1. Make an API call for a request token:

POST https://api.dropbox.com/1/oauth/request_token

 

Your HTTP request should have the following header:

Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="<app-key>", oauth_signature="<app-secret>&"

 

The response body will be a url-encoded string:

oauth_token=<request-token>&oauth_token_secret=<request-token-secret>

 

Parse out the request token and secret and save them somewhere."

 

 

 

 

 

I'm really struggling with how to send the header properly. 

 

Copying the example at http://brugbart.com/http-post-request-autoit, I have: 

; The data to be sent
$sPD = 'Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="h9y2pwy1nbvzy5e", oauth_signature="imrgkd8i80c2b8g&"'


; Creating the object
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "https://api.dropbox.com/1/oauth/request_token", False)
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
; Performing the Request
$oHTTP.Send($sPD)

; Download the body response if any, and get the server status response code.
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

If $oStatusCode <> 200 then
 MsgBox(4096, "Response code", $oStatusCode)
EndIf

; Saves the body response regardless of the Response code 
 $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists
 FileWrite($file, $oReceived)
 FileClose($file)

I think my Authorisation string should be used in the "SetRequestHeader" function, but am worried about replacing the "content-type" already there as it looks important.

 

 

If anybody can help it would be an enormous help

Link to comment
Share on other sites

Link to comment
Share on other sites

#include<WinHttp.au3>

Local $hOpen = _WinHttpOpen()
Local $hConnect = _WinHttpConnect($hOpen, "https://api.dropbox.com/1/oauth/request_token")
; Specify the reguest:
;Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "en-us/library/aa384101(VS.85).aspx")
Local $hRequest = _WinHttpOpenRequest($hConnect, "POST", 'Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="h9w2iwy1navzi5e", oauth_signature="imrgkd9i80b6o4o"')


; Send request
_WinHttpSendRequest($hRequest)

; Wait for the response
_WinHttpReceiveResponse($hRequest)

Local $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header

; Clean
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; Display retrieved header
MsgBox(0, "Header", $sHeader)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...