4

在添加我得到的参数后,我正在使用 RestClient 和 RestRequest 发出请求

错误:

Invalid URI: The URI string is too long. 

我假设这与未正确发布数据有关,这是我的代码:

RestClient client = new RestClient();
client.BaseUrl = "URL";
client.Authenticator =
    new HttpBasicAuthenticator("api",
            "KEY");
RestRequest restRequest = new RestRequest(Method.POST);
restRequest.AddParameter("domain",
            "DOMAIN", ParameterType.UrlSegment);
restRequest.Resource = "{domain}/messages";
restRequest.AddParameter("from", (string) sender["alias"] + "<email>");
restRequest.AddParameter("to", (string)recipient["alias"] + "<" + (string)recipient["email"] + ">");
restRequest.AddParameter("subject", subject);
restRequest.AddParameter("html", body);              
var result = client.Execute(restRequest);
if (result.StatusCode != System.Net.HttpStatusCode.OK)
{
     throw new Exception(result.ErrorMessage,new Exception(result.StatusCode + " - " + result.StatusDescription));
}

body 参数可能很长,因为它是 HTML 电子邮件。是什么导致了上述错误?

这是代码使用较短主体发出的请求,以便它确实发送 http://pastebin.com/HgbBHVpC

完整的堆栈跟踪,包括尝试发送http://pastebin.com/dRhXire6的消息

4

3 回答 3

0

http://msdn.microsoft.com/en-us/library/z6c2z492.aspx

查看它说的文档 uriString 的长度超过 65519 个字符

于 2012-12-19T14:59:11.623 回答
0

看起来像 RestSharp 的一个已知功能:

https://groups.google.com/forum/?fromgroups#!topic/restsharp/9b5bpK3gt9g

于 2014-07-11T04:09:09.203 回答
0

可能是request.AddParameter(contentTyp, ContentItself, ParameterType.RequestBody);request.AddBody。还可以尝试使用 fiddler 之类的东西来检查您发送的实际请求(url\body)。

于 2012-12-19T15:28:23.247 回答