Iphone didReceiveAuthenticationChallenge method - iphone

Actually, i m new for objective C.
I call webservice using NSURL. But that url consist XML argument.
example:
http://166:8081/application/service/ipad/saveGrowthRemark?remarksXML=
<empId>313009</empId>
<criteria>PT</criteria>
<type>Tamp;M</type>
<remarks>Enter Rmarks</remarks>
<cluster>ALL</cluster>
This is the code I used to retreibe the XML
-(void)createConnection{
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSURL *url=[NSURL URLWithString:_urlStr];
[request setURL:url];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
But this url does not called. Its return "bad URL" error.
what is the problem in this url.

As the error indicates there’s a problem with your URL. To me, the host part 166 doesn’t look valid.

Related

CFNetwork Error : The connection failed due to a malformed URL

While running iphone app, several times i got the following Error
The connection failed due to a malformed URL
At CFNetwork Error Codes Reference, i got the info that this error triggered by CFNetwork
When and Why this error is triggered ?
How to get rid from this error?
NSURLConnection has a method canHandleRequest which will return a boolean whether the url is valid or not, e.g.
NSString *strUrl = [NSString stringWithFormat:#"http://test.com/stopBoard/%i",busStopCode];
NSURL *url = [NSURL URLWithString:strUrl];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:20.0];
// a cache policy of NO must be used otherwise the previous query is used if the phone is not online
BOOL canGo = [NSURLConnection canHandleRequest:request];
if(canGo){
connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:YES];
} else {
self.errorMessage = #"\n\nurl check failed\n\n";
return NO;
}

OAMutableURLRequest - NSURLErrorDomain error -1012

I'm getting this error trying to post a request to hattrick.org using SAOAuthTwitterEngine Oauth authentication.
With all the GET requests everything works fine, but only one call must be in POST with a JSON string and this one doesn't work.
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn't be completed. (NSURLErrorDomain error -1012.).
I'm sure the request must be in http!
Here the code.
NSURL *finalURL = [NSURL URLWithString:path];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:finalURL
consumer:self.consumer
token:_accessToken
realm:nil
signatureProvider:nil];
[request setHTTPMethod:#"POST"];
[request setHTTPBody:[[NSData alloc]initWithContentsOfFile:body]];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest: request delegate: self didFinishSelector:#selector(testApiCallResult:didFinish:) didFailSelector: #selector(testApiCallResult:didFail:)];
return responseBodyToReturn;
I don't know how to solve this error.
I think that you occurred in a bug on the library...
Try with another, my suggestion is to use this:
gdata-objectivec-client

Do a GET request with parameters on iPhone SDK?

I'm doing an app which retrieves user info, and it does that using a GET request, but I don't know how could I make one. Already tried ASIHTTPRequest with this code:
NSURL *url = [NSURL URLWithString:#"http://forrst.com/api/v2/users/info"];
// Now, set up the post data:
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:#"1" forKey:#"id"];
[request setRequestMethod:#"GET"];
// Initiate the WebService request
[request setDelegate:self];
[request startAsynchronous];
But I get this response from forrst:
2011-06-05 16:59:32.189 Forrsty[4335:207] {"resp":{"error":"you must pass either id or username"},"stat":"fail","in":0.0557,"authed":false,"authed_as":false,"env":"prod"}
Which I understand I'm not doing the GET request ok, so how I would do it? Thanks :)
A Get Parameter ?
So why don't you try "http://forrst.com/api/v2/users/info?id=1" ?
[ NSString stringWithFormat:#"http://forrst.com/api/v2/users/info?id=%d", 1 ];
By the way, take a look at this librayry : http://allseeing-i.com/ASIHTTPRequest/
Good luck !

Serialized my in App "Shopping Cart" now trying to send it to a server using http Post - doesn't reach destination

I have a shopping cart in my app and an underlying data structure that I have serialized into an XML file. Im using the following code to place it on my server. However, nothing happens. Whe I check my server I donot find my file there. So I tried using just a string in place of the file and still the same. Nothing seems to be sent from the app to the server. Im running ths off the simulator.
Im wondering if there is anything wrong with this code.
CartSingleton *Cart = [CartSingleton getSingleton];
id xmlFile = [Cart serializeCart];
//Now send the xml file to the server
NSURL *url = [[NSURL alloc] initWithString:#"http://www.XXXXXXXXX.com/iOS_Files/xmlFile"];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
[req setHTTPMethod:#"POST"];
NSData *paramData = [xmlFile dataUsingEncoding:NSUTF8StringEncoding];
[req setHTTPBody:paramData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if(theConnection)
{
NSMutableData *data = [[NSMutableData alloc] init];
self.receivedData = data;
[data release];
}
else
{
NSLog(#"Unable to make connection!");
}
I would really appreciate any help.
Thanks
See the class reference, there you can also find the links for the sample applications.
That code
if(theConnection)
{
NSMutableData *data = [[NSMutableData alloc] init];
self.receivedData = data;
[data release];
}
does not start the connection. The receivedData property will have a new NSData object, which is then changed as the response data received.
For the better understanding of the NSUrlConnection usage follow that official guide
What you can do else is to test the server w/o the application using REST Client firefox extension (just send the post request with it and see what happens).
One possible problem with the above code (their may be others also), is that the connection setup will be asynchronous. This is why you had to supply a delegate object above. Therefore, the connection is not actually made until the delegate gets a callback to say it is ready.
Have you implemented any delegate methods?

creating JSON request URL in Objective C via DropBox SDK for iPhone

I'm rather new to trying to figure out how JSON and the DropBox API function with the iphone SDK that DB has release for the iPhone. I understand how both technologies work in general and that you have to build a dictionary into a request and get another dictionary back, but I can't find a solid example of how to do anything specifically enough online in Objective C.
I just need one example of how to retrieve for instance the user's profile information by creating a JSON request to fetch info from the drop-box server.
I've been able to log the user in and linking the device using the consumer key and consumer secret but what's next I'm a little at a loss.
MANY thanks for any guidance or examples.
To send your data
Example for POST methods:
url = #"https://api.dropbox.com/<version>/account/"
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:value forKey:#"callback"];
Example for GET methods (URL queries):
NSString *urlString = [[[NSString alloc] initWithString:#"https://api.dropbox.com/<version>/account/info
"] autorelease];
urlString = [urlString stringByAppendingFormat:#"?callback=whatever&status_in_response=something"];
NSURL *url = [[NSURL alloc] initWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:#selector(requestDidFinishForThreadID:)];
[request startAsynchronous];
To retrieve JSON values and convert them into Dictionary
SBJsonParser *json = [[SBJsonParser alloc] init];
NSDictionary *dict = (NSDictionary*)[json objectWithString:responseString];
You will need JSON Framework: http://code.google.com/p/json-framework/
And also ASIHTTPRequest: http://allseeing-i.com/ASIHTTPRequest/
Haven't tested it with dropbox, but should be this way.