我的手在空中 - 我哭了,叔叔。幫我理解:ASP.Net httpwebrequest沒有發帖請求身體
我寫了一個簡單的HttpWebRequest發佈到客戶端'https://website。 它具有特定的頭部要求和JSON請求主體。 GetResponseStream在收到GetResponse StatusCode.OK後,是由其服務器提供的錯誤。他們檢查他們的日誌,並表示,儘管頭存在,請求主體是」
這裏是我的代碼:
public const string API_URILogin = "https://dev.clientURL.com/test/api/login";
private void RequestTest()
{
LoginAPIStruct loginInfo = new LoginAPIStruct();
loginInfo.loginId = TestId;
loginInfo.password = TestPw;
loginInfo.vehicleType = "E";
loginInfo.deviceId = "ABCDEF";
loginInfo.clientId = "123456";
loginInfo.appVersion = string.Empty;
loginInfo.osType = string.Empty;
loginInfo.osVersion = string.Empty;
// Call LoginAPI
string loginStatus = LoginAPI(loginInfo);
//Display Results
lblResults.Text = loginStatus;
}
// Public Variables
public static string errorMessage;
// ** Client Login **
public static string LoginAPI(LoginAPIStruct loginInfo)
{
// Post Login to Client. Get response with Vehicle structure.
string loginInfoSerialized = string.Empty;
string returnString = string.Empty;
loginInfoSerialized = new JavaScriptSerializer().Serialize(loginInfo);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(API_URILogin);
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add("From", "CC");
request.Headers.Add("Language", "0");
request.Headers.Add("Offset", "-8");
request.Headers.Add("To", "CCM");
// Post Request
using (StreamWriter streamPost = new StreamWriter(request.GetRequestStream()))
{
streamPost.Write(loginInfoSerialized);
}
// Get Response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
// Status Okay.
//string responseStatusDescription = response.StatusDescription;
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
try
{
var result = streamReader.ReadToEnd();
returnString = result;
}
catch (Exception ex)
{
returnString = ex.Message;
}
}
}
else
{
returnString = response.StatusCode.ToString();
}
return returnString;
} // end LoginAPI
我的JSON字符串似乎是有效的 - 我把它粘貼到提琴手,隨着設置標題,並提琴手返回一個成功的登錄
從ASP.Net,它返回他們記錄的錯誤,電子郵件地址(loginId)是必需的我沒有看到任何不正確的C#代碼。否則看看?客戶可以在他們的託管網站上有東西阻止或過濾掉某個請求嗎?我被卡住了。
更新:我發現如何配置ASP.net讓Fiddler充當代理。 GlobalProxySelection.Select =新的WebProxy(「127.0.0.1」,8888); 我看到我的標題,但Content-Length設置爲0並且沒有內容正在發送。爲什麼? – IrvineCAGuy