http-request

Making stringWithContentsOfURL asynchronous - Is it safe?

一曲冷凌霜 提交于 2019-11-29 07:10:55
I attempted to make -[NSString stringWithContentsOfURL:encoding:error:] asynchronous, by running it a-synchronically from a background thread: __block NSString *result; dispatch_queue_t currentQueue = dispatch_get_current_queue(); void (^doneBlock)(void) = ^{ printf("done! %s",[result UTF8String]); }; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { result = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/"] encoding:NSUTF8StringEncoding error:nil]; dispatch_sync(currentQueue, ^{ doneBlock(); }); }); Its

Unable to locate FromStream in Image class

旧城冷巷雨未停 提交于 2019-11-28 19:17:56
I have the following code: Image tmpimg = null; HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream stream = httpWebReponse.GetResponseStream(); return Image.FromStream(stream); On the last line when I type in Image. , FromStream isn't in the list. What can I do? You probably need using System.Drawing; . More detailed out example with using and the namespaces needed. using System.Net; using System.IO; using System.Drawing; public static Image GetImageFromUrl(string url) {

Sending multipart/mixed content with Postman Chrome extension

十年热恋 提交于 2019-11-28 16:49:22
I'm struggling with creating POST multipart/mixed request with Postman Chrome extension Here is my curl request what works nice curl -H "Content-Type: multipart/mixed" -F "metadata=@simple_json.json; type=application/json " -F "content=@1.jpg; type=image/jpg" -X POST http://my/api/item -i -v interesting part of response Content-Length: 41557 Expect: 100-continue Content-Type: multipart/mixed; boundary=----------------------------8aaca457e117 additional stuff not fine transfer.c:1037: 0 0 HTTP 1.1 or later with persistent connection, pipelining supported And when I use Postman I getting such

How to send an HTTP request onbeforeunload in AngularJS?

笑着哭i 提交于 2019-11-28 12:08:24
I have a simple angular app that has two views that are loaded using ngRoute. I need to do some clean up on the server when the user navigates between views and when the user leaves the page (refreshes window, closes tab, or closes browser). My first stop was here: Showing alert in angularjs when user leaves a page . It solved the first case where the user navigates between views. I've handled the clean up like this: $scope.$on('$locationChangeStart', function (event) { var answer = confirm("Are you sure you want to leave this page?") if (answer) { api.unlock($scope.id); //api is a service

HTTP status code for unaccepted Content-Type in request

不羁的心 提交于 2019-11-28 10:39:38
For certain resources, my RESTful server only accepts PUT and POST requests with JSON objects as the content body, thus requiring a Content-Type of application/json instead of application/x-www-form-urlencoded or multipart/form-data or anything else. Malformed JSON (or lack thereof) returns a 400 with the error message taken directly from the exception raised by the JSON parser, for debugging purposes. Which HTTP error code means that the client sent a request with an unacceptable Content-Type , even if the server could technically parse the request content? William Durand It could be 415

Unknown encoding: idna in Python Requests

假装没事ソ 提交于 2019-11-28 07:14:26
问题 I'm using Python Requests. All works great but today I get this strange error: [...] File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/requests/models.py", line 321, in full_url netloc = netloc.encode('idna').decode('utf-8') LookupError: unknown encoding: idna Any ideas what could be wrong? I'm using Python 2.7.2 from brew. 回答1: Try adding: import encodings.idna in various places to sift out other errors. I ran into this same problem working on a port of python to a new

When should one use CONNECT and GET HTTP methods at HTTP Proxy Server?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 03:54:33
I'm building a WebClient library. Now I'm implementing a proxy feature, so I am making some research and I saw some code using the CONNECT method to request a URL. But checking it within my web browser, it doesn't use the CONNECT method but calls the GET method instead. So I'm confused. When I should use both methods? Anirudh Ramanathan A CONNECT request urges your proxy to establish an HTTP tunnel to the remote end-point. Usually is it used for SSL connections, though it can be used with HTTP as well (used for the purposes of proxy-chaining and tunneling) CONNECT www.google.com:443 The above

Getting HEAD content with Python Requests

我只是一个虾纸丫 提交于 2019-11-27 20:39:56
I'm trying to parse the result of a HEAD request done using the Python Requests library, but can't seem to access the response content. According to the docs , I should be able to access the content from requests.Response.text. This works fine for me on GET requests, but returns None on HEAD requests. GET request (works) import requests response = requests.get(url) content = response.text content = <html>...</html> HEAD request (no content) import requests response = requests.head(url) content = response.text content = None EDIT OK I've quickly realized form the answers that the HEAD request

how to post plain text to ASP.NET Web API endpoint?

﹥>﹥吖頭↗ 提交于 2019-11-27 19:18:31
I have an ASP.NET Web API endpoint with controller action defined as follows : [HttpPost] public HttpResponseMessage Post([FromBody] object text) If my post request body contains plain text ( i.e. should not be interpreted as json, xml, or any other special format ), then I thought I could just include following header to my request : Content-Type: text/plain However, I receive error : No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'text/plain'. If I change my controller action method signature to : [HttpPost] public HttpResponseMessage Post(

Android HTTP Request AsyncTask

僤鯓⒐⒋嵵緔 提交于 2019-11-27 14:32:34
I want to implement a class which will handle all HTTP Requests of my application, which will be basically: Get a list of business (GET); Execute a login (POST); Update the location (POST). So, I will have to get the result string from the server (JSON) and pass it to another methods to handle the responses. I currently have this methods: public class Get extends AsyncTask<Void, Void, String> { @Override protected String doInBackground(Void... arg) { String linha = ""; String retorno = ""; mDialog = ProgressDialog.show(mContext, "Aguarde", "Carregando...", true); // Cria o cliente de conexão