在本文中,我们将带你了解通过httpclient发送大json字符串在这篇文章中,我们将为您详细介绍通过httpclient发送大json字符串的方方面面,并解答httpclient发送json常见的
在本文中,我们将带你了解通过httpclient发送大json字符串在这篇文章中,我们将为您详细介绍通过httpclient发送大json字符串的方方面面,并解答httpclient 发送json常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的Android下通过HttpClient执行 HTTP POST 请求、android通过httpClient请求获取JSON数据并且解析、c# – 通过HttpClient发布文件时,HttpRequest.Files为空、c# – 通过带有HttpClient的HTTP POST Windows Phone 8.1上传图像和字符串。
本文目录一览:- 通过httpclient发送大json字符串(httpclient 发送json)
- Android下通过HttpClient执行 HTTP POST 请求
- android通过httpClient请求获取JSON数据并且解析
- c# – 通过HttpClient发布文件时,HttpRequest.Files为空
- c# – 通过带有HttpClient的HTTP POST Windows Phone 8.1上传图像和字符串
通过httpclient发送大json字符串(httpclient 发送json)
我通过两种方式解决了这个问题:
第一个解决方案:
将<requestLimits maxAllowedContentLength="52428800"/>
添加到 web.config 文件中的安全性>
我发现更干净的
第二个解决方案(MVC),请将以下内容添加到您的发布方法中:
[HttpPost]
[DisableRequestSizeLimit] // or
[RequestSizeLimit(50000000)] //50mb
public IActionResult UploadFile([FromBody] Data data)
{ }
感谢:https://www.talkingdotnet.com/how-to-increase-file-upload-size-asp-net-core/
Android下通过HttpClient执行 HTTP POST 请求
下面是小编 jb51.cc 通过网络收集整理的代码片段。
小编小编现在分享给大家,也给大家做个参考。
public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.yoursite.com/script.PHP"); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("id","12345")); nameValuePairs.add(new BasicNameValuePair("stringdata","AndDev is Cool!")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); } catch (ClientProtocolException e) { // Todo Auto-generated catch block } catch (IOException e) { // Todo Auto-generated catch block } }
以上是小编(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给程序员好友。
android通过httpClient请求获取JSON数据并且解析
android通过httpClient请求获取JSON数据并且解析:http://www.cnblogs.com/gzggyy/archive/2013/05/08/3066288.html
Android--使用Http向服务器发送请求并取得返回结果,下载图片:http://www.2cto.com/kf/201307/229489.html
Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据):http://blog.csdn.net/hewence1/article/details/46324799
c# – 通过HttpClient发布文件时,HttpRequest.Files为空
public HttpResponseMessage Post([FromUri]string machineName) { HttpResponseMessage result = null; var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0 && !String.IsNullOrEmpty(machineName)) ...
客户端:
public static void PostFile(string url,string filePath) { if (String.IsNullOrWhiteSpace(url) || String.IsNullOrWhiteSpace(filePath)) throw new ArgumentNullException(); if (!File.Exists(filePath)) throw new FileNotFoundException(); using (var handler = new httpclienthandler { Credentials= new NetworkCredential(AppData.UserName,AppData.Password,AppCore.Domain) }) using (var client = new HttpClient(handler)) using (var content = new MultipartFormDataContent()) using (var ms = new MemoryStream(File.ReadAllBytes(filePath))) { var fileContent = new StreamContent(ms); fileContent.Headers.Contentdisposition = new ContentdispositionHeaderValue("attachment") { FileName = Path.GetFileName(filePath) }; content.Add(fileContent); content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); var result = client.PostAsync(url,content).Result; result.EnsureSuccessstatusCode(); } }
在服务器端,httpRequest.Files集合始终为空.但标题(内容长度等)是正确的.
解决方法
public class UploadController : ApiController { public async Task<HttpResponseMessage> PostFile() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } string root = HttpContext.Current.Server.MapPath("~/App_Data"); var provider = new MultipartFormDataStreamProvider(root); try { StringBuilder sb = new StringBuilder(); // Holds the response body // Read the form data and return an async task. await Request.Content.ReadAsMultipartAsync(provider); // This illustrates how to get the form data. foreach (var key in provider.FormData.AllKeys) { foreach (var val in provider.FormData.GetValues(key)) { sb.Append(string.Format("{0}: {1}\n",key,val)); } } // This illustrates how to get the file names for uploaded files. foreach (var file in provider.FileData) { FileInfo fileInfo = new FileInfo(file.LocalFileName); sb.Append(string.Format("Uploaded file: {0} ({1} bytes)\n",fileInfo.Name,fileInfo.Length)); } return new HttpResponseMessage() { Content = new StringContent(sb.ToString()) }; } catch (System.Exception e) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError,e); } } }
c# – 通过带有HttpClient的HTTP POST Windows Phone 8.1上传图像和字符串
我看过其他帖子,但它不起作用,或者使用的类不存在.
我的功能的标题是:
public static async Task<bool> sendImagePerfil(string token,byte[] imagen) { using (var client = new HttpClient()) { var values = new List<keyvaluePair<string,string>>(); values.Add(new keyvaluePair<string,string>("token",token)); values.Add(new keyvaluePair<string,string>("image",Convert.ToString(imagen))); var content = new FormUrlEncodedContent(values); var response = await client.PostAsync("MyURL.domain/function",content); var responseString = await response.Content.ReadAsstringAsync(); } }
编辑:我现在的问题是我的服务器没有得到图像. django代码是:
if request.method == 'POST': form = RestrictedFileField(request.POST,request.FILES) token = models.UsuarioHasToken.objects.get(token=parameters['token']) user = token.user print (request.FILES['image']) user.image = request.FILES['image']
我无法修改django代码,因为此代码与Android应用程序一起使用
解决方法
How to upload file to server with HTTP POST multipart/form-data
试试这个……
HttpClient httpClient = new HttpClient(); MultipartFormDataContent form = new MultipartFormDataContent(); form.Add(new StringContent(token),"token"); var imageForm = new ByteArrayContent(imagen,imagen.Count()); imagenForm.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); form.Add(imagenForm,"image","nameholder.jpg"); HttpResponseMessage response = await httpClient.PostAsync("your_url_here",form); response.EnsureSuccessstatusCode(); httpClient.dispose(); string result = response.Content.ReadAsstringAsync().Result;
今天关于通过httpclient发送大json字符串和httpclient 发送json的介绍到此结束,谢谢您的阅读,有关Android下通过HttpClient执行 HTTP POST 请求、android通过httpClient请求获取JSON数据并且解析、c# – 通过HttpClient发布文件时,HttpRequest.Files为空、c# – 通过带有HttpClient的HTTP POST Windows Phone 8.1上传图像和字符串等更多相关知识的信息可以在本站进行查询。
本文标签: