I’m doing an ipad app. Actually, I’m converting a java applet application to the ipad version. I’ve got a lot of problems.
In the original java applet code, there are some http POST request, and it will receive some data from the java server.
httpCon=(HttpURLConnection) cmdURL.openConnection();
httpCon.setRequestMethod("POST");
httpCon.addRequestProperty("cmd", cmd);
httpCon.addRequestProperty("arg", arg);
httpCon.setDoInput(true);
and then, receive data:
inputStream=httpCon.getInputStream();
ObjectInputStream ois=new ObjectInputStream(inputStream);
Document doc=(Document)ois.readObject();
rData[2]=doc;
now, I want to do the same thing using objective-c:
NSURL * url = [NSURL URLWithString:@"http://192.168.1.4:801/cmd"];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"%@",cmd] forHTTPHeaderField:@"cmd"];
[request setValue:[NSString stringWithFormat:@"%@",arg] forHTTPHeaderField:@"arg"];
[NSURLConnection connectionWithRequest:request delegate:self];
_responseData is the data received:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
_responseData = [NSMutableData data];}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[_responseData appendData:data];
}
So, what should I do next? And there is a Document class in the java applet code, is there any similar class in the objective-c?
=======UPDATE=======
the java server returns the xml as the Document instance. Can I use the _responseData as an xml file directly? Or I have to do additional steps before dealing with the _responseData?
you cant use java object streams in objC. It is meant to send java object
… well in thoery you could IF you reverse engineered the protocol the objectStream uses but that’s a lot of work and a maintenance hell (I guess) –
I would look into Using a common exchange format.. json or xml maybe!
after your edit:
I dont know the xml the objectstream sends but in theory you can just parse it and setup a custom objC class with it.
I also dont know what the Document class is or does or where its from so I cant say if there’s an equivalent in Java. I tend towards no.