iOS: How can i receive HTTP 401 instead of -1012 NSURLErrorUserCancelledAuthentication

Yes. Stop using the synchronous API. If you use the asynchronous delegate-based API then you have a lot more control over the connection. With this API, except in cases where an error is encountered before the HTTP header is received, you will always receive -connection:didReceiveResponse:, which gives you access to the HTTP header fields (encapsulated … Read more

Problem using NSURLRequest to POST data to server

You should remove the leading & in myRequestString and the problem is likely that the correct content-type header is not being sent. Try adding a call to [request setValue:@”application/x-www-form-urlencoded” forHTTPHeaderField:@”content-type”]; You should also not pass nil for error, so you can see what the client thinks is going on. Unrelated, but your PHP code is … Read more

In Node.js / Express, how do I “download” a page and gets its HTML?

var util = require(“util”), http = require(“http”); var options = { host: “”, port: 80, path: “” }; var content = “”; var req = http.request(options, function(res) { res.setEncoding(“utf8”); res.on(“data”, function (chunk) { content += chunk; }); res.on(“end”, function () { util.log(content); }); }); req.end();

Calling Express Route internally from inside NodeJS

The ‘usual’ or ‘correct’ way to handle this would be to have the function you want to call broken out by itself, detached from any route definitions. Perhaps in its own module, but not necessarily. Then just call it wherever you need it. Like so: function updateSomething(thing) { return; } // elsewhere: router.put(‘/api/update/something/:withParam’, function(req, … Read more

Making a HTTP GET request with HTTP-Basic authentication

Marc B did a great job of answering this question. I recently took his approach and wanted to share the resulting code. <?PHP $username = “some-username”; $password = “some-password”; $remote_url=””; // Create a stream $opts = array( ‘http’=>array( ‘method’=>”GET”, ‘header’ => “Authorization: Basic ” . base64_encode(“$username:$password”) ) ); $context = stream_context_create($opts); // Open the file … Read more

Get HTTP Status Code in Android WebView

It’s not possible (as of the time i’m writing this). The docs for onReceiveError() are ambiguous at best, but it you look at this issue, It’s clear that HTTP status codes won’t be reported through that mechanism. How it’s possible that the developers wrote WebView with no way to retrieve the HTTP status code … Read more

How can I use an HTTP proxy for a JAX-WS request without setting a system-wide property?

I recommend using a custom ProxySelector. I had the same problem and it works great and is super flexible. It’s simple too. Here’s my CustomProxySelector: import org.hibernate.validator.util.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import; import; import; import; import*; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; /** * So the way a ProxySelector works is that … Read more