How do I make a request using HTTP basic authentication with PHP curl?

You want this: curl_setopt($ch, CURLOPT_USERPWD, $username . “:” . $password); Zend has a REST client and zend_http_client and I’m sure PEAR has some sort of wrapper. But its easy enough to do on your own. So the entire request might look something like this: $ch = curl_init($host); curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/xml’, $additionalHeaders)); curl_setopt($ch, CURLOPT_HEADER, 1); … Read more

Returning data from async call in Swift function

You can pass callback, and call callback inside async call something like: class func getGenres(completionHandler: (genres: NSArray) -> ()) { … let task = session.dataTaskWithURL(url) { data, response, error in … resultsArray = results completionHandler(genres: resultsArray) } … task.resume() } and then call this method: override func viewDidLoad() { Bookshop.getGenres { genres in println(“View Controller: … Read more

HTTP GET with request body

Roy Fielding’s comment about including a body with a GET request. Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind. Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request. … Read more

How do I POST JSON data with cURL?

You need to set your content-type to application/json. But -d (or –data) sends the Content-Type application/x-www-form-urlencoded, which is not accepted on Spring’s side. Looking at the curl man page, I think you can use -H (or –header): -H “Content-Type: application/json” Full example: curl –header “Content-Type: application/json” \ –request POST \ –data ‘{“username”:”xyz”,”password”:”xyz”}’ \ http://localhost:3000/api/login (-H … Read more