简体   繁体   English

来自webservice的回复

[英]Response from webservice

I am consuming a web service made in php, I have already answered from Postman I get data, but when doing the implementation in C # through RestSharp, I get a connection but I do not get content. 我正在使用php制作的web服务,我已经从Postman回答了我得到的数据,但是当我在C#中通过RestSharp进行实现时,我得到了一个连接,但我没有得到内容。

Try in a Xamarin App and in a Console App, but I can not get the content. 尝试使用Xamarin应用程序和控制台应用程序,但我无法获取内容。

        var client = new RestClient("https://www.test.com/app/ws.php/");
        var request = new RestRequest(Method.POST);
        request.AddHeader("cache-control", "no-cache");
        request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
        request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"reqedu\"\r\n\r\nget-data-alum\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"appusr\"\r\n\r\nuser\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"apppwd\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);

After the execute method, you need check response code whether the request is successful or not from response object something like this 执行方法之后,您需要检查响应代码,无论请求是否成功,都来自响应对象

  IRestResponse response = client.Execute(request);
  if (response.StatusCode == System.Net.HttpStatusCode.OK)
      Console.WriteLine(response.Content);
  else
      Console.WriteLine(response.ErrorMessage);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM