注::この前にvb.netコードを記述したことはありません。私は解決策を探りましたが、うまく機能しているものは見つかりませんでした。VB.NET - Salesforce POSTリクエストで400の不正なリクエストエラーが返される
Salesforceからアクセストークンを取得しようとしています。 コードはちょうど昨日でした。そして、なぜそれが今日働いていないのか分かりません。私はコンテンツタイプをapplication/x-www-form-urlencodedとして追加しようとしましたが、うまくいきませんでした。私がカールを使用するとき、私はアクセストークンを得ることができます。また、私はGoogle Chromeで高度なレストクライアントを使用してアクセストークンを取得することができます。それが返されている理由は何ですか400 Bad Request不明なエラーを再試行しますか?
Imports System.Collections.Specialized
Imports System.Net
Imports System.Text
Module Module1
Sub Main()
Dim clientId As String = "clientId"
Dim clientSecret As String = "clientSecret"
Dim redirectUri As String = "https://test.salesforce.com"
Dim environment As String = "https://test.salesforce.com"
Dim tokenUrl As String = ""
Dim username As String = "[email protected]"
Dim password As String = "passwordtoken"
Dim accessToken As String = ""
Dim instanceUrl As String = ""
Console.WriteLine("Getting a token")
tokenUrl = environment + "/services/oauth2/token"
Dim request As WebRequest = WebRequest.Create(tokenUrl)
Dim values As NameValueCollection = New NameValueCollection()
values.Add("grant_type", "password")
values.Add("client_id", clientId)
values.Add("client_secret", clientSecret)
values.Add("redirect_uri", redirectUri)
values.Add("username", username)
values.Add("password", password)
request.Method = "POST"
Try
Dim client = New WebClient()
Dim responseBytes As Byte() = client.UploadValues(tokenUrl, "POST", values)
Dim response As String = Encoding.UTF8.GetString(responseBytes)
Console.WriteLine(response)
Console.ReadKey()
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.WriteLine("Press any key to close")
Console.ReadKey()
End Try
End Sub
End Module
あなたは400応答を取得するときに、応答本体には何ですか? – superfell
出力responseBytesを試しましたが、nullが表示されます。また、デバッグモードでは、それをnullとして表示します。 – tugce
私はこれを何年も使っていませんが、覚えていることから、特定の例外があります。そのエラー状態のレスポンスボディにアクセスできます。 – superfell