ASIHttpRequest: Can someone see the URL being sent? - ios

I'm using ASIHttpRequest to send data back and forth to the server in my IOS game.
I'm wondering if someone can see the url being send to the server, someway?
... If that's the case, cheating is possible.
thanks in advance
The request looks like this:
NSURL *url = [NSURL URLWithString: #"http://xx.xxx.xx.x/development/"];
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL: url];
__weak ASIHTTPRequest *request_b = request;
[request setDelegate: self];
[request setQueue: [[DatabaseHelper sharedInstance] networkQue]];
[request setShouldContinueWhenAppEntersBackground: NO];
[request addRequestHeader:#"Content-Type" value:#"text/html; charset=utf-8;"];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
[request setTimeOutSeconds: 20.0f];
[request setCachePolicy: ASIDoNotWriteToCacheCachePolicy | ASIDoNotReadFromCacheCachePolicy];
[request setPostValue:#"aSecretString" forKey:#"secret"];
[request setPostValue: #"updateUser" forKey:#"apiToRun"];
[request setPostValue: #"4" forKey:#"userId"];
url:
http://xx.xxx.xx.x/development/secret=aSecretString&apiToRun=updateUser&userId=4

With a GET request, data is sent as part of the URL and is easy to intercept with HTTP monitoring. If you use POST, this information will not be visible in the URL.

Related

Posting to a Google Forms form using NSURLRequest

I am trying to post a string to a Google Form using NSURLRequest. The method seems to be getting called, but the post to the Google Form doesn't appear. This is the code I am using:
NSURL *requestURL = [NSURL URLWithString:#"https://docs.google.com/forms/d/1T9M6B_k4tiQcSPP5iS2jyU7DCkoRC1jFVql_eQDy9ek/formResponse"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[request setHTTPMethod:#"POST"];
NSString *postString = #"entry.757751040=Test sent from iOS App";
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"content-type"];
if (connection){
NSLog(#"Connecting...");
}
I created this form solely for testing purposes. "Connecting..." gets logged, so I know the connection is being made, but the string does not appear in the Google Forms Spreadsheet. Am I doing something wrong? Any help would be greatly appreciated.
This piece of code only checks if connection is not nil
if (connection){
NSLog(#"Connecting...");
}
is equivalent to
if (connection != nil){
NSLog(#"Connecting...");
}
As such, it has nothing to do with an actual connection to the URL.
The method initWithRequest:(NSURLRequest *)request delegate:(id)delegate which you are using will perform the request immediately. This means that you have to perform the operations in another order if you want your params to work:
NSURL *requestURL = [NSURL URLWithString:#"https://docs.google.com/forms/d/1T9M6B_k4tiQcSPP5iS2jyU7DCkoRC1jFVql_eQDy9ek/formResponse"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:#"POST"];
NSString *postString = #"entry.757751040=Test sent from iOS App";
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"content-type"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Along with this, consider implementing NSURLConnectionDelegate.

ASIHttpRequest not passing data

NSURL *url = [NSURL URLWithString:#"http://test.com/misc/app/ws/ws_user_registration.php?"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:#"POST"];
[request setDelegate:self];
[request appendPostData:[[NSString stringWithFormat:#"{\"user_name\":\"%#\",\"user_tag_status\":\"%#\",\"description\":\"%#\",\"mobile_number\":\"%#\",\"device_type\":\"%#\",\"device_id\":\"%#\",\"device_token\":\"%#\",\"os\":\"%#\",\"os_version\":\"%#\",\"image_data\":\"%#\",\"user_id\":\"%#\"}",self.phnNumTxtFld.text,#"live",#"description",self.phnNumTxtFld.text,#"iPhone",appDelegate.deviceID,appDelegate.deviceToken,#"iOS",[UIDevice currentDevice].systemVersion,[data base64EncodedString],#""] dataUsingEncoding:NSUTF8StringEncoding]];
[request setDidFinishSelector:#selector(getTreeRequestFinished:)];
[request setDidFailSelector:#selector(getTreeRequestFailed:)];
[request startAsynchronous];
appendPostData: passing NSData but server not getting this data.
To post data use ASIFormDataRequest
NSURL *url = [NSURL URLWithString:#"http://test.com/misc/app/ws/ws_user_registration.php?"];
ASIFormDataRequest* asiRequest = [ASIFormDataRequest requestWithURL: url];
[asiRequest setPostFormat:ASIMultipartFormDataPostFormat];
[asiRequest addData:DATA_TO_SEND withFileName:FILE_NAME andContentType:FILE_CONTENT_TYPE forKey:YOUR_FILE_UPLOADKEY;
[asiRequest setDidFinishSelector:#selector(connectionFinishedLoading:)];// called when connection successfully got finished and recieve resoponse
[asiRequest setDidFailSelector:#selector(requestWentWrong:)]; // called when connection went wrong due to bad url connection or timeout, etc.
[asiRequest setDelegate:self];
[asiRequest startAsynchronous];
For more info read asihttp docs

Upload Image with dictionary

I want to upload image to server from iphone. Using ASIHttpRequest and ASIFormDataRequest i have sucessfully uplaoded picture to server by
[request setdata:...]
But I also want to send userId to server with image. How to achieve this? Here is my code...
ASIFormDataRequest *_request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:URLSaveImage]];
__unsafe_unretained ASIFormDataRequest *request = _request;
[ASIHTTPRequest setShouldThrottleBandwidthForWWAN:YES];
[request setUploadProgressDelegate:self];
NSData *data=UIImageJPEGRepresentation(proImage.image,1.0);
[request setData:data
withFileName:#"profile.jpg"
andContentType:#"image/jpeg"
forKey:#"file"];
For POST method, use setPostValue: forKey: with the setdata:. You dont need to do any additional work . Just post the variable along with image.
[request setPostValue:VALUE forKey:KEY];
[request setData:data withFileName:#"profile.jpg" andContentType:#"image/jpeg"
forKey:#"file"];

IOS: ASIFormDataRequest with quotation marks

I have to send json to a web service that only accepts it via a POST variable.
ASIFormDataRequest insists on escaping my quotation marks.
any help would be appreciated
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSString *body = [NSString stringWithFormat:#"{\"user\":\"username\",\"pass\":\"password\"}"];
[request setPostValue:body forKey:#"body"];
[request startSynchronous];
output: "{\"user\":\"username\",\"pass\":\"password\"}"
Try Converting the parameter into JSON representation before sending it through SBJSON or whatever JSON parser you are using.
JosephH is right
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request appendPostData:[dataString dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:#"POST"];
[request startSynchronous];
was the way to go.

ASIHTTPRequest POST for basecamp

Hi I am using ASIHTTPRequest POST for adding time entry on basecamp for logged in user.
But
- (void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders
method of ASIHTTPRequest is getting called and in
- (void)requestFailed:(ASIHTTPRequest *)request
I am getting error as access denied.
I also need to send aunthentication token to basecamp URl please help me how to do this.
NSString *postData=[NSString stringWithFormat: #"<time-entry>\
<person-id> 898989 </person-id>\
<date>2011-04-07</date>\
<hours>2:00</hours>\
<description>test</description>\
</time-entry>"];
NSURL *url = [NSURL URLWithString:#"https://test.basecamphq.com/projects/4644/time_entries.xml"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request setRequestMethod:#"POST"];
[request appendPostData:[postData dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];
[request addRequestHeader:#"Accept" value:#"application/xml"];
[request addRequestHeader:#"Content-Type" value:#"application/xml"];
[request authenticationNeeded];
[request setValidatesSecureCertificate:NO];
[request startAsynchronous];
This is my code. Please help.
Assuming this is the right API doc:
http://developer.37signals.com/basecamp/
Then basecamp using HTTP basic authentication, meaning you need to do this:
[request setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeBasic];
[request setUsername:yourApiToken];
[request setPassword:#"X"];
Putting your API token where it says 'yourApiToken'.

Resources