I have the following code used to post data to a remote server:
NSString *urlStr = [[NSString alloc] initWithFormat: #"http://www.myserver.com/%#",program ];
NSString *postBody =[[NSString alloc] initWithFormat:#"uid=%#",parms];
NSMutableURLRequest *request;
NSData *postData = [postBody dataUsingEncoding:NSISOLatin1StringEncoding];
NSError *error;
NSURLResponse *response;
NSData *dataReply;
request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:urlStr]];
[request setHTTPMethod: #"POST"];
[request setHTTPBody:postData];
dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
serverResponse = (NSString *)[[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
[postBody release];
[urlStr release];
program is the php program to run on the server. parms is the string to be posted in the format:
\ntoken=12345
Here's the problem: This works fine from the simulator. It works fine on my 3gs development phone. It works fine on a beta tester's 3gs phone that I emailed the app to. It does NOT work fine on another beta tester's iPhone 4 (emailed to him the exact same provision file and ipa file). The POST call is made from the iPhone 4 to the server but no post body is passed. I log each of the calls to the server on the server. The post body is there for the 3gs phones, not for the 4 phone. There are no errors generated in the Apache logs.
Is there some difference between the two phone models that I need to account for? I have tried both http and https access with the same behavior. I don't currently have access to an iPhone 4 so any insight would be a great help.
The answer is not model related. It has to do with the name of the phone which is passed as a parameter to the server. The name contains an apostrophe as in Mike's iPhone.
Related
i have sign up form in which i have the fields like first name,last name,gender,email,password,user image,age. i want to make save this user information on the server through php webservice call.how can i pass these parameters to service url? will i use the http request using post method to save the user info to server and when that user wants to log in iOS app , i may match the credencial for that user. in shore, i need a log in and sign up screen for my iOS app, please suggest me any tutorial
Thanks in advance to all of you
First you need nto create php script and then transfer data through NSURL.
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:#"http://192.168.0.6/savedevicedata.php?Udid=%#&Flag=%d&DateTime=%#",uniqueIdentifier,Flag,FinalDate]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSLog(#"%#",request);
[request setHTTPMethod:#"POST"];
//[request setHTTPBody:[NSString stringWithFormat:#"%#",rawStr]];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(#"responseData: %#", responseData);
Try this Code just replaces the your field.
I installed the WordPress blog on my localhost server and also made an iPhone app to browse the blog via rss. I tried to post a comment programmatically using this code.
#define post_url #"http://localhost/web-wp/wp-comments-post.php"
#define post_content #"comment_post_ID=%#&comment_parent=%#&author=%#&email=%#&comment=%#"
NSString *post_str = [NSString stringWithFormat:post_content, #"1", #"0", #"Viet", #"vietnt88#gmail.com", #"test. comment written on mobile"];
NSData *data = [post_str dataUsingEncoding:NSUTF8StringEncoding];
NSURL * url = [NSURL URLWithString:post_url];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
[req setHTTPMethod:#"POST"];
[req setHTTPBody:data];
NSURLResponse *response;
NSError *err;
[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
I need this code to work when the user is not logged in. How do I achieve that?
How can I post comment from iPhone?
First of all, if you use "localhost" from your code running on your iPhone, then "localhost" will refer to the iPhone not to your web server. Put there the IP of your server, if you have a public IP than that one otherwise connect your iPhone via WiFi to the same LAN as your local server and use the IP of that server (I guess it'll be something like 192.168...).
This may be a simple question but i'm a newer to web service programming.
What i need is to send a recipe to a database and the administrator has to approved it.
I'm handling with the server side program for the first time.sorry for this.
So can anyone kindly help me how to send large datas from iphone to webservice.
Thanks in advance.
For example : Suppose You want to pass user name and password to server. Then you can pass it with the web services. By :
NSString *urlStr = [NSString stringWithFormat:#"%#?method=login&emailId=%#&Password=%#&iphonekey=%#",aWebserviceURL,username,password,aIphoneKey];
NSLog(#"Login - %#",urlStr);
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
NSMutableData *responseData;
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding] autorelease];
NSLog(#"%#",responseString);
Here username,password,aIphoneKey are the Parameters of web service.
I'm assuming you're meaning from an iPhone app to webserver?
If that's the case there's a decent article on making web requests in Objective C here
And a good intro here also
I am trying to download a xyz.config file which is created using iPhone Configuration utlity, via code.
NSString *urlString = #"http://xxxxx:xxx/ms/servlet/ConfigServer?userid=xxx&pwd=xxx&emailid=xxxxx";
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
receivedData = [[NSMutableData data] retain];
} else {
// Inform the user that the connection failed.
}
Then, didReceiveData, didReceiveResponse are written. Finally,
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(#"Succeeded! Received %d bytes of data",[receivedData length]);
NSString *responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(#"Response : %#", responseString );
// release the connection, and the data object
[receivedData release];
[connection release];
}
With the above code, i'm getting response as string of the complete configuration file. But my Aim to download this file as raw data, which will automatically launch device profile to ask for installing this profile.
NOTE: I am able to provide the same URL in Safari browser on the device, and download the
raw file directly to install it on the device. I don't want to use Safari browser to download it, it should be done via my communication code.
I also tried with ASIHTTPRequest like below, but unable to download that file directly from the URL via this code as well.
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:#"GET"];
[request startSynchronous];
Please help!
Thank you.
The Mobile Safari browser app on the iOS has a lot more freedom than your app. Case in point, on the latest iOS 4.3, Mobile Safari has the Nitro JavaScript engine which boost 2x performance increase. But the UIWebView which is available to your app doesn't have that engine. Your app is in a sandbox, therefore, you cannot write outside of that box.
Hi everyone i am new to iphone development.I am working on an application which required to check and register the user name and password using soap web service.could anyone help me how to do that with that web service.i have two text fields for login.and button to check if the credentials are correct or not.
Maybe this is helpful for you: http://devmylife.com/?p=111
The website disappeared, you can find it here: http://web.archive.org/web/20100704000223/http://devmylife.com/?p=111
ASIHTTP SOAP Request
First of all down http://www.soapui.org/ or any packet sniffing app. and try requesting your SOAP-service. When you get the SOAP-packet, you have to exactly generate the same packet using ASIHTTP. You have to add headers yourself.
Download latest version of ASIHTTP
NSString *urlString = URL_HOST;
NSString *soapMessage = [NSString stringWithFormat:#"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
"<SOAP-ENV:Body>"
"<m:getInboxPosts xmlns:m=\"urn:finditnearwsdl\">"
"<input xsi:type=\"tns:InboxPostsRequest\">"
"<session_id xsi:type=\"xsd:string\">%#</session_id>"
"<page_size xsi:type=\"xsd:int\"></page_size>"
"<offset xsi:type=\"xsd:int\"></offset>"
"</input>"
"</m:getInboxPosts>"
"</SOAP-ENV:Body>"
"</SOAP-ENV:Envelope>" ,adBo.sessionId];
NSLog(soapMessage);
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:urlString];
[request appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding];
[request addRequestHeader:#"SOAPAction:" value:SOAP_ACTION];
[request startSynchronous];