You can log the error to find out what the problem is. Replace this part in your code:
...
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"error: %@", error);
}
...
Question
trying to implement a noddy web service in a java server with an iOS client
java service is listening on a local port then kicking off a response thread which is returning
public void run() {
try {
InputStream input = clientSocket.getInputStream();
OutputStream output = clientSocket.getOutputStream();
long time = System.currentTimeMillis();
output.write(("HTTP/1.1 200 OK\n\nWorkerRunnable: " + this.serverText + " - Hello Phil!" +time +"").getBytes());
output.close();
System.out.println(input);
System.out.println(output);
input.close();
System.out.println("Request processed: " + time);
} catch (IOException e) {
//report exception somewhere
e.printStackTrace();
}
iOS client is sending request
NSLog(@"testing...");
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:9000"]];
// Initialize Request Operation
AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:URL]];
// Configure Request Operation
[requestOperation setResponseSerializer:[AFJSONResponseSerializer serializer]];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *response;
response = [responseObject responseString];
NSLog(@" %@ ", response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failed");
}];
// Start Request Operation
[requestOperation start];
NSLog(@"connecting...");
iOS returns fail every time - i can hit it from my browser , i can see my java server sending the data back -
am i returning the data wrong? what format should i use? can't seem to find a simple example any where its all JSON/XML SOAP/etc
thanks in advance
Phil
La solution
You can log the error to find out what the problem is. Replace this part in your code:
...
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"error: %@", error);
}
...