c#要求Webサービス書き方
1891 ワード
///
/// webservice
///
///
///
/// webservice
private string RequestWebService(string url, string sendData)
{
string backMsg = "";
WebResponse response = null;
try
{
WebRequest httpRquest = HttpWebRequest.Create(url);
httpRquest.Method = "POST";
// , ContentType
httpRquest.ContentType = "application/x-www-form-urlencoded;utf-8";
byte[] dataArray = Encoding.UTF8.GetBytes(sendData);
Stream requestStream = null;
if (string.IsNullOrWhiteSpace(sendData) == false)
{
requestStream = httpRquest.GetRequestStream();
requestStream.Write(dataArray, 0, dataArray.Length);
requestStream.Close();
}
response = httpRquest.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
backMsg = reader.ReadToEnd();
reader.Close();
reader.Dispose();
requestStream.Dispose();
responseStream.Close();
responseStream.Dispose();
}
catch (Exception ex)
{
logger.Error(" : \t" + ex.GetType());
logger.Error(" :\t" + ex.Message);
logger.Error(" :\t" + ex.TargetSite);
logger.Error(" :\t" + ex.StackTrace);
}
return backMsg;
}