如何在c#中使用webRequest类Multible命令发送cURL/API请求

本文关键字:命令 cURL 请求 API Multible webRequest | 更新日期: 2023-09-27 18:03:57

我需要发送这个服务器:

curl https://api.placetel.de/api/getRouting.xml '
    -d 'api_key=xxxxxxxxxxxxxxxxxxx' '
    -d 'number=068111111XXX'

如果我尝试:

            WebRequest request = WebRequest.Create("https://api.placetel.de/api/getRouting.xml");
            request.Method = "POST";
            string postData = "api_key=XXXXXXXXXXXXXXX number=0685123XXXXXX";
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();
            listBox1.Items.Add(responseFromServer);

我得到一个登录错误- API不正确,因为我的程序发送API + number=在"一行"

问题是我如何像两个命令一样发送它?我尝试与字符串postData &postData1也不工作

:

string postData1 = "'nnumber=068567909000";
  byte[] byteArray1 = Encoding.UTF8.GetBytes(postData1);

如何在c#中使用webRequest类Multible命令发送cURL/API请求

添加ContentType,并使用&分隔每个参数:

request.ContentType = "application/x-www-form-urlencoded";
var postData = "api_key=XXXXXXXXXXXXXXX";
postData += "&number=0685123XXXXXX";