.net
  • vb.net
  • httpwebrequest
  • google-drive-sdk
  • 2012-12-29 228 views 0 likes 
    0

    我試圖創建一個HTTP請求,以獲得一個新的accesstoken與存儲的refreshtoken,所以我可以訪問谷歌驅動器。httpsrequest谷歌驅動器refreshtoken

    Dim uri As String = "https://accounts.google.com/o/oauth2/token" 
    
        Dim para As String = "code='" + cred.RefreshToken + "'&client_id='" + ClientCredentials.CLIENT_ID + "'&client_secret='" + ClientCredentials.CLIENT_SECRET + "'&grant_type='refresh_token'" 
    
        Dim httpWebRequest As System.Net.HttpWebRequest = Net.WebRequest.Create(uri) 
        httpWebRequest.Method = "POST" 
        httpWebRequest.ContentType = "application/x-www-form-urlencoded" 
    
        Dim requestStream As System.IO.Stream = httpWebRequest.GetRequestStream() 
        Dim streamwriter As System.IO.StreamWriter = New System.IO.StreamWriter(requestStream) 
        streamwriter.Write(para) 
        streamwriter.Close() 
    
        Dim httpWebResponse As System.Net.HttpWebResponse = httpWebRequest.GetResponse() 
    

    但是這會返回一個錯誤的請求。我錯過了什麼?

    回答

    0

    你是不是寫您的憑據到StreamWriter的,它應該讀...

    streamwriter.Write(para) 
    

    這是假設他們是正確的,當然。

    +0

    對不起,這是一個錯字。還有什麼可以發送錯誤的請求(400)? – user1936674

    相關問題