嘗試發送JSON的HttpRequest到SFDC Web服務時,得到如下回應:傳遞登錄信息發送的HttpRequest到SFDC Web服務
[1]
0: {
message: "Session expired or invalid"
errorCode: "INVALID_SESSION_ID"
}
如何正確地傳遞會話ID或LoginResult與HttpRequest的另一個信息?代碼示例如下:
// Generate JSON
MyClass object = new MyClass();
string post_data = JsonSerializer.SerializeToString(object); // this is what we are sending
// this is where we will send it
string uri = "https://url.salesforce.com/some_path/";
// create a request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.KeepAlive = false;
request.Method = "POST";
byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
request.ContentType = "application/json";
request.ContentLength = postBytes.Length;
// Setup proxy and SFDC login
LoginResult result = SfdcConnection.GetLoginResult();
// ------------ Need to add login info here -----------------
// now send it
Stream requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
// grab te response and print it out to the console along with the status code
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string jsonResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();
它將取決於您試圖調用哪個api,請求的實際url是什麼? – superfell
對不起,沒提 - REST –
找到了一些文檔,似乎需要先發送auth請求。 –