cURL到C#(500)内部服务器错误

时间:2015-11-26 01:56:18

标签: c# curl

尝试将cURL转换为C#

curl -v -X POST -d '{"signature":"2d0c311eb0fe9cd84fcd1b875759c313","marker":"PutYourMarkerHere","host":"beta.aviasales.ru","user_ip":"127.0.0.1","locale":"ru","trip_class":"Y","passengers":{"adults":1,"children":0,"infants":0},"segments":[{"origin":"MOW","destination":"LED","date":"2015-05-25"},{"origin":"LED","destination":"MOW","date":"2015-06-18"}]}' -H 'Content-type:application/json' http://api.travelpayouts.com/v1/flight_search

这是我的代码,它有什么问题?我收到500内部服务器错误

        var data = "{'signature':'2d0c311eb0fe9cd84fcd1b875759c313','marker':'72872','host':'mysite.com','user_ip':'112.199.36.67','locale':'ru','trip_class':'Y','passengers':{'adults':1,'children':0,'infants':0},'segments':[{'origin':'MOW','destination':'LED','date':'2015-05-25'},{'origin':'LED','destination':'MOW','date':'2015-06-18'}]}";
        var request = (HttpWebRequest)WebRequest.Create(new Uri("http://api.travelpayouts.com/v1/flight_search"));
        request.Method = "POST";
        request.AllowAutoRedirect = false;
        request.Accept = "*/*";
        request.ContentType = "application/json";
        request.ContentLength = data.Length;

        using (var reqStream = request.GetRequestStream())
        using (var writer = new StreamWriter(reqStream))
        {
            writer.Write(data);
        }

        var response = request.GetResponse();
        MessageBox.Show(response.Headers.ToString());

0 个答案:

没有答案