Note that there are some explanatory texts on larger screens.

plurals
  1. POAFHTTPRequest result null (even though I can see JSON in browser)
    text
    copied!<p>I am using a GET request to get JSON data.</p> <p>The call looks like this:</p> <pre><code>-(void)getJSON{ //Where request is going AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://localhost:1234"]]; //Parameters NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:@"/test" parameters:nil]; //Init operation AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]]; //Set completion block [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { //Handle response NSLog(@"Request succesful"); NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { //Code to execute if failed NSLog(@"Error: %@", error); }]; //Initiate request [operation start]; } </code></pre> <p>When I query on my browser I get this:</p> <pre><code>{"Object 2":"Lemon","Object 1":"Chicken"} //http://localhost:1234/test </code></pre> <p>This response is sent by my method on the server (in java):</p> <pre><code>/** * Sends reply back to client * @throws Exception */ private void sendResponse() throws Exception{ HashMap&lt;String, String&gt; mapResponse = new HashMap&lt;String, String&gt;(); mapResponse.put("Object 1", "Chicken"); mapResponse.put("Object 2", "Lemon"); //Convert to JSON Gson gson = new Gson(); String json = gson.toJson(mapResponse); //write out as JSON responseToClient.writeBytes(json); } </code></pre> <p>Not sure why xcode isn't handling the response... When I look at the value in the debugger it says responseObject = x0000000 (null)</p> <p><img src="https://i.stack.imgur.com/Jtljz.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload