Using the Office365 iOS library I want to implement the send message functionality.
The code below, by running the sample code returns an error:
NSURLSessionDataTask* task = [[[client getMe] getOperations] sendMail:message :true :^(int returnValue, MSODataException *error) {
NSLog(#"Error: %#", error);
[task resume]; }];
Error Domain=Error in the Request Code=400 "The operation couldn’t be completed. (Error in the Request error 400.)" UserInfo=0x7cb3eee0 {error={
code = ErrorInvalidRequest;
message = "Cannot read the request body.";}}
Does anyone know a fix for this? It could be caused by a wrong sent payload message?
That error does indicate a problem with the request payload. The common case is a missing Content-Type header. Can you capture a network trace and confirm? Also make sure you're using the latest release of that library.
Related
Am trying to integrate instagram in my app,while getting user details after getting access token,its showing error . Am appending data in NSData and trying to print it in connectionDidFinishLoading(NSURLConnection *)connection ( NSURLConnection Delegate) . While converting NSData to id ,its showing null .Also if i am converting NSdata to NSString am getting Response as
{"meta":{"error_type":"OAuthAccessTokenException","code":400,"error_message":"The access_token provided is invalid."}}{"meta":{"code":200},"data":{"username":"XXXX","bio":"","website":"","profile_picture":"http:sampleiamge.jpg","full_name":"samplename","counts":{"media":1,"followed_by":0,"follows":0},"id":"sampleID"}}
If am printing the json as id jsonData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
getting error as
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be
completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0xa967bc0
{NSDebugDescription=Garbage at end.}
Tried all jsonreading option ,but no result
Any hep will be appreciable.
Thanks
You could also have a look at the InstagramKit which does this fairly straight forward. https://github.com/shyambhat/InstagramKit
There's a demo app so you can see how the authentication is done and request a user's details in just a few lines of code. You don't really need to mess around with the access token data format.
It seems like you are not authenticate.
There is a project in GitHub that implements a simple UIViewController that performs the Instagram auth process step by step:
https://github.com/Buza/Instagram-Auth-iOS
You can see all process from request token to error management.
Hope it helps!
The response occurs when the access_token is invalid, try printing (NSLog) out the URL your are making the request and make sure the access_token is correctly passed.
It looks simple, but don't know what goes wrong. I am trying to load a basic URL in WebView, as shown below
WebsiteWebView.delegate=self;
NSURL* url = [NSURL URLWithString:#"http://firstclasspizzaoc.com/"];
[WebsiteWebView loadRequest:[NSURLRequest requestWithURL:url]];
while loading i am getting below error everytime..
Error : Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0xe036d20 {NSErrorFailingURLKey=http://firstclasspizzaoc.com/, NSErrorFailingURLStringKey=http://firstclasspizzaoc.com/}
2014-01-07 15:18:46.142 FirstClassPizza[1583:
Error : Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo=0xe0ef310 {NSErrorFailingURLStringKey=XXXXXXXX, NSErrorFailingURLKey=XXXXXXXX, NSLocalizedDescription=A server with the specified hostname could not be found., NSUnderlyingError=0xcbe9130 "A server with the specified hostname could not be found."}
At Browser it is loading perfectly..
Please suggest what went wrong in my code..
Any Valuable suggestions will be appreciated...
Thanks
It is due to Your Web URL http://firstclasspizzaoc.com/ can you use your url with
http://www.firstclasspizzaoc.com/
You can find your answer here :
How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS
This thread contained this description for this error: "This error may occur if an another request is made before the previous request of WebView is completed..."
I worked around this by ignoring this error and letting the webview continue to load.
if ([error code] != NSURLErrorCancelled) {
//show error alert, etc.
}
I have been stuck with this for a while and don't seem to get around this.
I am trying to read the contents of an URL as a string from an URL, But i get a weird
Error -> Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
My code :
fetchedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:#"www.example.com/iphone"] encoding:NSUTF8StringEncoding error:&error];
NSLog(#"%#",fetchedString);
// if there is something wrong with the URL
if (error) {
NSLog(#"Error -> %#", error);
return ;
}
What am I doing wrong? I tried using getting as NSData as well, but I get null back.
Yes, the URL is missing the scheme: "http://".
"Error -> Error Domain=NSCocoaErrorDomain Code=256"
For the error code check the Apple documentation:
NSError codes in the Cocoa error domain.
NSFileReadUnknownError = 256,
NSFileReadUnknownError
"Read error, reason unknown"
Not that the error definition is very helpful. :-)
Also do not check if error is nil to determine if there is an error, check the return value for nil. error is not guaranteed to be nil on successful execution.
I had a similar problem accessing files located on my device. I followed NSURL isFileURL always returns NO
and used [NSURL fileURLWithPath] instead of [NSURL URLWithString] - this worked!
I got this error (Error Domain=NSCocoaErrorDomain Code=256) as soon as our ssl certificate expired. that may not help you but could help someone else.
Sandboxing
If you're using sandboxing in your app, you might want to check that com.apple.security.network.client is set to YES. It's in the the General tab of your Target in Xcode 5 under
Network: Outgoing Connections (Client)
Also be aware that if you see a code 257 when trying to reach a file:/// url, that's also probably because of sandboxing, but this time rather the File Access part. Because I didn't want to open it to anything else than `com.apple.security.files.user-selected.read-write'
User selected files
I preferred to use A Dead Simple Fileserver and use http://localhost:3000 when in Debug mode.
More reasons that might be causing this specific error:
SSL is misconfigured on the server
The server redirects (301) the http URL to https (see #1)
App transport security also uses this code for blocked requests.
I got the same error. The above marked answer is perfect. But in my case, I had the "http://" in the url but had to add the port number in the url request since there is a service running on a specific port that is actually responding to your request.
#"http://example.com:8084/yyy.zzz"
I got the same error, the above solution didn't work for me, in my case i was calling dataWithContentsOfURL from within a UNNotificationServiceExtension so i had to update the info.plist file of the UNNotificationServiceExtension with the app transport security entries.
I'm using the exact sample code from the AFNetworking README to download a file, but the request is immediately cancelled:
File downloaded to: (null) with response = (null) and error = Error Domain=NSURLErrorDomain Code=-999 "cancelled"
I thought another request might be canceling this one out in my larger application, so I created a new sample project with just one button that just does this download. So I know that isn't the case.
Googling for a solution only returned information about how to voluntarily cancel an existing request.
It is a problem about redirections. Happens with 302 and 301 redirections.
I resolve the problem setting on the AFURLSessionManager object this block:
[manager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) {
return NSURLSessionAuthChallengePerformDefaultHandling;
}];
I found the solution here: AFNetworking 2.0: NSURLSessionDownloadTask is cancelled when received 302 to AWS S3
The server was responding with a 302 and the request was canceling itself. I had no way of knowing that unfortunately until I did a curl on the command line.
I'm getting a weird behavior where using sendSynchronousRequest or sendAsynchronousRequest with invalid credential will make the nsurlresponse nil. But the old way with the [[NSURLConnection alloc] initWithRequest:request delegate:self]; I get the 401 response code.
The error value using the sendSynchronousRequest or sendAsynchronousRequest is
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be
completed. (NSURLErrorDomain error -1012.)" UserInfo=0x756ecb0
{NSErrorFailingURLKey=myurl,
NSErrorFailingURLStringKey=myurl,
NSUnderlyingError=0x75704d0 "The operation couldn’t be completed.
(kCFErrorDomainCFNetwork error -1012.)"
Does someone have a clue as to why it is like that? Any information on this is appreciated. I was expecting to get a 401 response from sendSynchronousRequest or sendAsynchronousRequest
Thanks,
This error is caused when a WWW-Authenticate: HTTP header is returned with the 401 response, asking for user-interaction to enter valid credentials. The NSURLConnection processes the HTTP headers and the response body, returning the response data correctly as an NSData object, but leaving the returningResponse object as nil.
According to Apple's Foundation Constants Reference, the error -1012 is:
NSURLErrorUserCancelledAuthentication
Returned when an asynchronous request for authentication is cancelled by the user.
This is typically incurred by clicking a “Cancel” button in a username/password dialog, rather than the user making an attempt to
authenticate.
I am speculating that it automatically treats the WWW-Authenticate: header as a request for credentials that was cancelled by the user (since it is headless) and generates the error. Then some other part of the code-path that should set the response is not executed because there was an error. Personally I think this is either a bug or bad design. It should be ok to get a valid HTTP response and an error at the same time, either way, you get a valid HTTP response so the returningResponse should be set. Bad Apple!