zwei1121

博客园 首页 新随笔 联系 订阅 管理

HttpClient client = new HttpClient();
var content = new FormUrlEncodedContent(new Dictionary<string, string>() {
{ "number", "09129457000" }
});
client.DefaultRequestHeaders.Referrer = new Uri("http://sim.mci.ir/first-step");

var resp = await client.PostAsync("http://sim.mci.ir/chk-number-availability", content);
var repsStr = await resp.Content.ReadAsStringAsync();

 

 

async Task<string> GetResponseString(string text)
{
var httpClient = new HttpClient();

var parameters = new Dictionary<string, string>();
parameters["text"] = text;

var response = await httpClient.PostAsync(BaseUri, new FormUrlEncodedContent(parameters));
var contents = await response.Content.ReadAsStringAsync();

return contents;
}
And your final function call:

Task<string> result = GetResponseString(text);
var finalResult = result.Result;
Or even better:

var finalResult = await GetResponseString(text);

 

//var httpClient = new HttpClient();
//string responseJson = httpClient.GetAsync(string.Format("", Phone, Message))
// .Result.Content.ReadAsStringAsync().Result;


var url = "";
var postData = new Dictionary<string, string>
{
{ "cdkey", "" },
{ "password", "" },
{"phone" ,""},
{"message" ,""}
};
var urlEncodedContent = new FormUrlEncodedContent(postData);
var httpClient = new HttpClient();
var result = httpClient.PostAsync(url, urlEncodedContent).Result.Content.ReadAsStringAsync().Result;

posted on 2017-10-19 16:10  zwei  阅读(241)  评论(0编辑  收藏  举报