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
Related
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;
}
I am integrating Twilo sdk to my iPhone app.
NSString *urlString=#"urlstring";
NSURL* url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request startSynchronous];
NSString *response=[request responseString];
NSLog(#"Response:%#",response);
NSDictionary *dict=[response JSONValue];
NSMutableString *capabilityToken=[[NSMutableString alloc] initWithFormat:#"%#",[dict objectForKey:#"message"]];
device = [[TCDevice alloc] initWithCapabilityToken:capabilityToken delegate:nil];
I am getting response as
{"message":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJBQzYwYTFlOTMxOTI5NmFhNmFlZDcwZjhkYjZhMTQyNGJmIiwiZXhwIjoxMzM3NzU5MTA3LCJzY29wZSI6InNjb3BlOmNsaWVudDpvdXRnb2luZz9hcHBTaWQ9QVAxODRlNTE3YzZmN2EyZGI5NTkwMzM5N2I3NWRkMDliMSJ9.fXjQhBaXu3OlN_zXZIvSkoElphtQuW1QnNSbmUzfsSc"}
Assigning that string to TCDevice object while initializing I am getting following exception.
-[__NSCFString PJSTRString]: unrecognized selector sent to instance 0x77a21d0
Can anyone please help me the reason for this exception and how to solve it.
Thanks in advance.
Try adding the flags '-ObjC -all_load' to the "Other Linker Flags" in your target's Build Settings
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.
I have the following requirement to call a service using an ASIHTTPRequest with a POST method call. When I execute the request I get the following error:
errorError Domain=ASIHTTPRequestErrorDomain Code=5 "Unable to create request (bad url?)" UserInfo=0x790b490 {NSLocalizedDescription=Unable to create request (bad url?)}
And heres my code:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:SampleURL]];
[request addPostValue:#"emailid" forKey:username.text];
[request addPostValue:#"password" forKey:password.text];
[request addPostValue:#"first_name" forKey:first_name];
[request addPostValue:#"last_name" forKey:last_name];
[request addPostValue:#"option" forKey:#"userSignup"];
request.delegate = self;
[request startSynchronous];
Can anyone help me on this?
NSString *safestring=[strUrl stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url= [NSURL URLWithString:safestring];
[request addPostValue:#"emailid" forKey:username.text];
Shouldn't that be in the opposite order: [request addPostValue:username.text forKey:#"emailid"];
Same for the rest...
It looks like that 'sampleURL' has some issue. What is the data type of sampleUL? it should be NSURL.
Also what is in sampleURL when this piece of code is executed.
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 !