1. C#调用接口
- 需求就是A服务端要调用B服务端暴露的接口,并且发送数据
2.废话不多说看我的思路
3.标准方法请求
```csharp
try
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(serviceAddress);
httpWebRequest.Credentials = new NetworkCredential("wechatPush", "OA");
httpWebRequest.Method = "POST";
httpWebRequest.ContentType= "application/json";
using (var stremWriter=new StreamWriter(httpWebRequest.GetRequestStream()))
{
stremWriter.Write(contentJson);
stremWriter.Flush();
stremWriter.Close();
}
string response = string.Empty;
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpWebRequest.GetRequestStream(), Encoding.UTF8))
{
response = streamReader.ReadToEnd();
};
}
catch(Exception ex)
{
throw new Exception(serviceAddress + contentJson + ex.Message);
}
4.注意的地方
5.后面你的接口调试的时候就可以拦截到请求了
搞定非常的简单