HttpClient: The uri string is too long

后端 未结 4 751
青春惊慌失措
青春惊慌失措 2020-12-17 10:00

Given the following attempt to post data to a web service that generates PDF files, PDF rocket (which is awesome by the way).

I get the err

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 10:48

    @Mick Byrne : Thanks - your solution worked like a charme!

    Here is my complete code:

          public async Task DateienSendenAsync (string PfadUndDatei, string Dateiname, String VRPinGUID, String ProjektGUID, String VRPinX, String VRPinY, String VRPinZ)
        {
            var client = new HttpClient();
            // Create the HttpContent for the form to be posted.
            var requestContent = new[] {
                                new KeyValuePair("dateiname", Dateiname),
    
                                new KeyValuePair("bild", Convert.ToBase64String(File.ReadAllBytes(PfadUndDatei))),
                                new KeyValuePair("VRPinGUID", VRPinGUID),
                                new KeyValuePair("ProjektGUID", ProjektGUID),
                                new KeyValuePair("ebene", "ebene"),
                                new KeyValuePair("raumnummer", "raumnummer"),
                                new KeyValuePair("ansichtsname", "ansichtsname"),
                                new KeyValuePair("VRPinX", VRPinX),
                                new KeyValuePair("VRPinY", VRPinY),
                                new KeyValuePair("VRPinZ", VRPinZ),
    
                                };
    
            String url = "http://yourhomepage/path/upload.php";
    
            var encodedItems = requestContent.Select(i => WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value));
            var encodedContent = new StringContent(String.Join("&", encodedItems), null, "application/x-www-form-urlencoded");
    
            // Post away!
            var response = await client.PostAsync(url, encodedContent);
    
    
    
        }
    

提交回复
热议问题