Note that there are some explanatory texts on larger screens.

plurals
  1. POdataWithContentsOfURL - What is expected from the server?
    primarykey
    data
    text
    <p>I am trying to create NSData with the contents of an URL:</p> <pre><code>NSString *theUrl = [NSString stringWithString:@"http://127.0.0.1:8090"]; NSError *connectionError = nil; NSData *inData = [NSData dataWithContentsOfURL:[NSURL URLWithString:theUrl] options:NSDataReadingUncached error:&amp;connectionError]; NSInteger code = [connectionError code]; if (code != 0) { NSString *locDesc = [NSString stringWithString:[connectionError localizedDescription]]; NSString *locFail = [NSString stringWithString:[connectionError localizedFailureReason]]; NSLog(@"Error: %d %@ %@", code, locDesc, locFail); } else if ([inData length] == 0) { NSLog(@"No data"); } </code></pre> <p>I have a super simple Java http server running on the local host that returns Hello World to a client:</p> <pre><code>DataOutputStream os = new DataOutputStream(s.getOutputStream()); // s is the socket os.writeBytes(new String("Hello World\0")); os.flush(); os.close(); s.close(); </code></pre> <p>When pointing Google Chrome to <a href="http://127.0.0.1:8090" rel="nofollow">http://127.0.0.1:8090</a> it displays Hello World as expected so data <em>is</em> sent back. When I run the objective-c code the inData is empty (0x0, data length is 0), and the error code is 0 so I don't have an error to inspect. If I change theUrl to "http://www.google.com" it seems works fine as the data length becomes > 0.</p> <p>So my question is why inData is empty when I go the to local http-server. Does the stream have to be terminated with a specific data sequence? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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