HttpWebResponse から 500 エラー応答メッセージを取得する必要があります。
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
{
post_response = responseStream.ReadToEnd();
responseStream.Close();
}
ありがとうございました!
[編集]
ブラウザを使用してこの URL を開き、
ブラウザーは、応答メッセージ「Missing parameter: M_ID.」を出力します。
今、asp.netを使用してその応答メッセージを取得したい
var post_string = "hello=hi";
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("https://www.sagepayments.net/web_services/vterm_extensions/transaction_processing.asmx/BANKCARD_PRIOR_AUTH_SALE");
objRequest.Method = "POST";
objRequest.ContentLength = post_string.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
// post data is sent as a stream
StreamWriter myWriter = null;
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(post_string);
myWriter.Close();
// returned values are returned as a stream, then read into a string
try
{
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
{
post_response = responseStream.ReadToEnd();
responseStream.Close();
}
Response.Write(post_response);
}
catch(WebException e)
{
Response.Write("Error : "+e.Message);
Response.Write("<br /> Data : " + e.Data);
Response.Write("<br /> HelpLink : " + e.HelpLink);
Response.Write("<br /> InnerException : " + e.InnerException);
Response.Write("<br /> Response : " + e.Response);
Response.Write("<br /> Source : " + e.Source);
Response.Write("<br /> Status : " + e.Status);
Response.Write("<br /> TargetSite : " + e.TargetSite);
}
Result :
Error : The remote server returned an error: (500) Internal Server Error.
Data : System.Collections.ListDictionaryInternal
HelpLink :
InnerException :
Response : System.Net.HttpWebResponse
Source : System
Status : ProtocolError
TargetSite : System.Net.WebResponse GetResponse()
このメッセージを取得する方法?
パラメータがありません: M_ID。