0

RestSharp の使用 C# を使用して Windows フォーム アプリケーションから Web サービスを使用して、デスクトップ アプリケーションを作成したいと考えています。

最初のリクエストからのレスポンスを取得していますが、別のリクエストを送信するとタイムアウト エラーが発生します。これがコードです

client = new RestClient();

client.BaseUrl = "webservicelink";

client.Authenticator = new DigestAuthenticator("usrnm", "pswd");

var request = new RestRequest();

request.AddParameter("key",JVP8xGk4hsX2cZd0L3NQwYbI0mf4exPiSoAhVYnz");

IRestResponse response = client.Execute(request);
4

1 に答える 1

0

応答が有効であることを確認し、次の要求のために Cookie を保存する必要があると思います。このようなものがうまくいくかもしれません:

if (response.StatusCode != HttpStatusCode.OK && response.StatusCode !=   HttpStatusCode.Created)
{
     throw new Exception(response.Content);
}
RestResponseCookie cookie = response.Cookies[0];

var anotherRequest = new RestRequest();
anotherRequest.AddCookie(cookie.Name, cookie.Value);
anotherRequest.AddHeader("content-type", "application/xml");
...
IRestResponse anotherResponse = client.Execute(anotherRequest);

それが役立つことを願っています

于 2013-08-29T08:47:03.373 に答える