Html编码工作,但当我转换为C#它显示错误,我怎么能将HTML代码更改为C# [英] Html coding working, but when I convert to C# it shows error, how can I change the HTML code to C#

查看:57
本文介绍了Html编码工作,但当我转换为C#它显示错误,我怎么能将HTML代码更改为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<form method="post" action="http://pudhukadai.co.in/api/bus/search_trip.php">
<textarea name="request">
{"uid": "xxxx","pin": "xxxx","source_id": "1270","destination_id": "323","date": "05-05-2017"}
</textarea>
 
 <input type="submit" name="submit" value="submit">
</form>





我尝试了什么:





What I have tried:

WebRequest request = (WebRequest)WebRequest.Create("http://pudhukadai.co.in/api/bus/search_trip.php?uid=xxxx&pin=xxxx&source_id=1270&destination_id=323&date=25-04-2017");
request.Method = "post";
request.ContentType = "application/json; charset=utf-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string result = reader.ReadToEnd();

推荐答案

string json = "{\"uid\": \"xxxx\",\"pin\": \"xxxx\",\"source_id\": \"1270\",\"destination_id\": \"323\",\"date\": \"05-05-2017\"}";
var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
using (var httpClient = new HttpClient())
{
    // Error here
    var httpResponse = await httpClient.PostAsync("http://pudhukadai.co.in/api/bus/search_trip.php", httpContent);
    if (httpResponse.Content != null)
    {
        // Error Here
        var responseContent = await httpResponse.Content.ReadAsStringAsync();
    }
}



你可能想看看Newtonsoft.Json来处理创建Json字符串。


and you may want to look at Newtonsoft.Json to handle creating the Json string.


这篇关于Html编码工作,但当我转换为C#它显示错误,我怎么能将HTML代码更改为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆