具有500错误代码的HttpClient MultipartFormDataContent后置请求

时间:2017-05-03 03:56:42

标签: c# httpclient

var client = new HttpClient();
        client.DefaultRequestHeaders.Add("ApiKey", "xxxxxxxxxxxxxxxxxxxxx");

        var values = new[]
       {
        new KeyValuePair<string, string>("signer[email]", "mrafi127@yahoo.com"),
        new KeyValuePair<string, string>("signer[first_name]", "Rafi"),
        new KeyValuePair<string, string>("signer[last_name]", "Qureshi"),
        new KeyValuePair<string, string>("transaction_name", "Miguel's TPS notarization for Leeroy"),
        new KeyValuePair<string, string>("transaction_type", "Power of Attorney"),
        new KeyValuePair<string, string>("message_to_signer", "Please notarize your TPS Report"),
        new KeyValuePair<string, string>("message_signature", "Love, Leeroy."), 
        };

        var content = new MultipartFormDataContent();
        foreach (var keyValuePair in values)
        {
            content.Add(new StringContent(keyValuePair.Value),
                String.Format("\"{0}\"", keyValuePair.Key));
        }

        content.Add(new StreamContent(System.IO.File.Open(HostingEnvironment.MapPath("~/Content/Individual_Formx.pdf"), FileMode.Open)), "document", "Image.pdf");

        var result = client.PostAsync("https://api.notarize.com/v1/transactions", content);
        result.Wait();
        Console.WriteLine(result.Result.ToString());

它给出了以下结果 ID = 61,状态= RanToCompletion,方法=&#34; {null}&#34;,结果=&#34; StatusCode:500,ReasonPhrase:&#39;内部服务器错误&#39;,版本: 1.1,内容:System.Net.Http.StreamContent,Headers:\ r \ n {\ r \ n \ n \ n \ n访问控制 - 允许 - 原点:* \ r \ n变化:原点\ r \ n X-Kong-Proxy-Latency :3 \ r \ n X-Kong-Upstream-Latency:10968 \ r \ n X-Request-Id:6daf37b5-16b6-47d1-87bb-8e3a3798d4f0 \ r \ n X-Runtime:0.379850 \ r \ n连接:保持-alive \ r \ n日期:2017年5月3日星期三01:59:36 GMT \ r \ n服务器:Cowboy \ r \ n Via:kong / 0.9.7 \ r \ n内容长度:1477 \ r \ n内容类型:text / html;字符集= UTF-8 \ r \ N}&#34;

0 个答案:

没有答案