.net post請求接口


public static string GetStringByHttpPostRaw(string url, string data)
{
string value = "";
log.Info(url);
log.Info(data);
//RentInterfaceReturnModel model;
try
{
HttpWebRequest reqest = (HttpWebRequest)WebRequest.Create(url);
reqest.Method = "POST";
reqest.ContentType = "application/json";
Stream stream = reqest.GetRequestStream();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(data);
stream.Write(bs, 0, bs.Length);
stream.Flush();
stream.Close();
HttpWebResponse response = (HttpWebResponse)reqest.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
value = sr.ReadToEnd();
response.Close();
return value;
}
catch (Exception ex)
{
//model = new RentInterfaceReturnModel();
//model.resultCode = "102";
//model.message = ex.Message.ToString();
//return JsonMapper.ToJson(model);
log.Info(ex.Message);
return "102";

}

 


}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM