part 1:
AWSStaticCredentialsProvider *credentials = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:#"xxxxxxxxxxx" secretKey:#"xxxxxxxxxxxx"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionAPNortheast1 credentialsProvider:credentials];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
[AWSDDLog sharedInstance].logLevel = AWSDDLogLevelVerbose;
[AWSDDLog addLogger:[AWSDDTTYLogger sharedInstance] ];
part 2:
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.bucket = #"bucket";
uploadRequest.key = #"tarpath";
uploadRequest.body = [NSURL fileURLWithPath: srcPath];
[[transferManager upload:uploadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id(AWSTask *task) {
if (task.error) {
if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain])
{return nil;}];
}
info.plist has prepared the ATS problem
Below is The error log:
content-encoding:aws-chunked
content-type:binary/octet-stream
host:s3-ap-northeast-1.amazonaws.com
transfer-encoding:Chunked
user-agent:aws-sdk-iOS/2.5.9 iOS/10.2.1 zh_CN transfer-manager
x-amz-content-sha256:STREAMING-AWS4-HMAC-SHA256-PAYLOAD
x-amz-date:20170813T133010Z
x-amz-decoded-content-length:78670
content-encoding;content-type;host;transfer-encoding;user-agent;x-amz-content-sha256;x-amz-date;x-amz-decoded-content-length
STREAMING-AWS4-HMAC-SHA256-PAYLOAD]
2017-08-13 22:30:10:521 test[1026:597507] AWS4 String to Sign: [AWS4-HMAC-SHA256
20170813T133010Z
20170813/ap-northeast-1/s3/aws4_request
7b0dac3ee72f93ad197c7dd6277c2cf5779e6f13c7009e405cafeb765c45eeb0]
2017-08-13 22:30:10:523 test[1026:597507] Request headers:
{
Authorization = "AWS4-HMAC-SHA256 Credential=xxxxxxxxxxxxx/20170813/ap-northeast-1/s3/aws4_request,
SignedHeaders=content-encoding;content-type;host;transfer-encoding;user-agent;x-amz-content-sha256;x-amz-date;x-amz-decoded-content-length,
Signature=f91f3f9002bfe3ae7ec39c71846efd7c99bdf72d5f8163ac400d476f1055b7e7";
"Content-Encoding" = "aws-chunked";
"Content-Type" = "binary/octet-stream";
Host = "s3-ap-northeast-1.amazonaws.com";
"Transfer-Encoding" = Chunked;
"User-Agent" = "aws-sdk-iOS/2.5.9 iOS/10.2.1 zh_CN transfer-manager";
"X-Amz-Date" = 20170813T133010Z;
"x-amz-content-sha256" = "STREAMING-AWS4-HMAC-SHA256-PAYLOAD";
"x-amz-decoded-content-length" = 78670;
}
2017-08-13 22:31:11:117 test[1026:597507] Session task failed with error: Error Domain=NSURLErrorDomain Code=-1001 "要求逾時。"
UserInfo={NSUnderlyingError=0x171056e90 {Error
Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)"
UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}},
NSErrorFailingURLStringKey=https://s3-ap-northeast-1.amazonaws.com/zxmdata/thevoice/56334401838871229471503493680_Wanmei2017.aac,
NSErrorFailingURLKey=https://s3-ap-northeast-1.amazonaws.com/zxmdata/thevoice/56334401838871229471503493680_Wanmei2017.aac,
_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=要求逾時。}
2017-08-13 22:31:11.161499 test[1026:597374] Error: Error Domain=NSURLErrorDomain Code=-1001 "要求逾時。"
UserInfo={NSUnderlyingError=0x171056e90 {Error
Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)"
UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}},
NSErrorFailingURLStringKey=https://s3-ap-northeast-1.amazonaws.com/zxmdata/thevoice/56334401838871229471503493680_Wanmei2017.aac,
NSErrorFailingURLKey=https://s3-ap-northeast-1.amazonaws.com/zxmdata/thevoice/56334401838871229471503493680_Wanmei2017.aac,
_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=要求逾時。}
Error message says it is a NSErrorFailingURLStringKey error.
The url in error message has a typo, - in https:
h-ttps://s3-ap-northeast-1.amazonaws.com/zxmdata/thevoice/56334401838871229471503493680_Wanmei2017.aac
Related
I am using AFNetworking 3.1.0 to make a http request.
It shows below after i made the request. The code i made the request is in the bottom. The url below you can see is not visitable without ssl VPN.
Error Domain=com.alamofire.error.serialization.response Code=-1011
"Request failed: forbidden (403)"
UserInfo={com.alamofire.serialization.response.error.response= { URL:
https://223.71.215.70/web/1/http/0/10.100.5.105:6666/entry } { status
code: 403, headers {
Connection = "Keep-Alive";
"Content-Length" = 238;
"Content-Type" = "text/html; charset=iso-8859-1";
Date = "Wed, 14 Dec 2016 14:27:48 GMT";
"Keep-Alive" = "timeout=15, max=100";
"X-Frame-Options" = SAMEORIGIN; } }, NSErrorFailingURLKey=https://223.71.215.70/web/1/http/0/10.100.5.105:6666/entry,
NSLocalizedDescription=Request failed: forbidden (403),
com.alamofire.serialization.response.error.data=<3c21444f 43545950
45204854 4d4c2050 55424c49 4320222d 2f2f4945 54462f2f 44544420
48544d4c 20322e30 2f2f454e 223e0a3c 68746d6c 3e3c6865 61643e0a
3c746974 6c653e34 30332046 6f726269 6464656e 3c2f7469 746c653e
0a3c2f68 6561643e 3c626f64 793e0a3c 68313e46 6f726269 6464656e
3c2f6831 3e0a3c70 3e596f75 20646f6e 27742068 61766520 7065726d
69737369 6f6e2074 6f206163 63657373 202f7765 622f312f 68747470
2f302f31 302e3130 302e352e 3130353a 36363636 2f656e74 72790a6f
6e207468 69732073 65727665 722e3c2f 703e0a3c 2f626f64 793e3c2f
68746d6c 3e0a>} Request failed: forbidden (403)
let config = URLSessionConfiguration.default
config.timeoutIntervalForRequest = 30
let manager = AFHTTPSessionManager(sessionConfiguration: config)
manager.requestSerializer = AFHTTPRequestSerializer() // AFJSONRequestSerializer(writingOptions: .prettyPrinted)
manager.responseSerializer = AFHTTPResponseSerializer() // AFJSONResponseSerializer(readingOptions: .mutableContainers)
// manager.responseSerializer.acceptableContentTypes = ["text/html"]
manager.responseSerializer.acceptableContentTypes = ["application/json", "text/json", "text/JavaScript", "text/html", "text/plain"]
let policy = AFSecurityPolicy(pinningMode: .none)
policy.allowInvalidCertificates = true
policy.validatesDomainName = false
manager.securityPolicy = policy
manager.post(url, parameters: para, progress: nil, success: { (task:URLSessionDataTask, a:Any?) in
print(123)
}) { (task: URLSessionDataTask?, error: Error) in
// print(task?.description)
print(error)
print(error.localizedDescription)
}
I found that if my phone clock was out of sync...Maybe check that your phone is set to the right time "auto zone" and see if that works...
Reference URL: https://community.fitbit.com/t5/Charge-HR/Can-t-set-up-error-Forbidden-403/td-p/1053680
I am trying to print JSON response in first log.But whenever i try to get response from this URL and also from this URL .But whenever i make a request i am getting this error.
NSErrorFailingURLKey=http://wptrafficanalyzer.in/p/demo1/first.php/countries/, NSLocalizedDescription=Request failed: unacceptable content-type: text/html, com.alamofire.serialization.response.error.data
This is my Log File
2016-01-15 12:19:25.618 JSOnParsingWithActorList[3153:58905] Error: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x78e25230> { URL: http://wptrafficanalyzer.in/p/demo1/first.php/countries/ } { status code: 200, headers {
"Cache-Control" = "max-age=3600";
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 490;
"Content-Type" = "text/html";
Date = "Fri, 15 Jan 2016 06:27:55 GMT";
Expires = "Fri, 15 Jan 2016 07:27:55 GMT";
"Keep-Alive" = "timeout=5, max=100";
Server = "Apache/2.2.22 (Ubuntu)";
Vary = "Accept-Encoding";
"X-Powered-By" = "PHP/5.3.10-1ubuntu3.21";
} }, NSErrorFailingURLKey=http://wptrafficanalyzer.in/p/demo1/first.php/countries/, NSLocalizedDescription=Request failed: unacceptable content-type: text/html, com.alamofire.serialization.response.error.data=<7b22636f 756e7472 69657322 3a5b7b22 636f756e 7472796e 616d6522 3a22496e 64696122 2c22666c 6167223a 22687474 703a5c2f 5c2f7770 74726166 66696361 6e616c79 7a65722e 696e5c2f 705c2f64 656d6f31 5c2f696e 6469612e 706e6722 2c226c61 6e677561 6765223a 2248696e 6469222c 22636170 6974616c 223a224e 65772044 656c6869 222c2263 75727265 6e637922 3a7b2263 6f646522 3a22494e 52222c22 63757272 656e6379 6e616d65 223a2252 75706565 227d7d2c 7b22636f 756e7472 796e616d 65223a22 50616b69 7374616e 222c2266 6c616722 3a226874 74703a5c 2f5c2f77 70747261 66666963 616e616c 797a6572 2e696e5c 2f705c2f 64656d6f 315c2f70 616b6973 74616e2e 706e6722 2c226c61 6e677561 6765223a 22557264 75222c22 63617069 74616c22 3a224973 6c616d61 62616422 2c226375 7272656e 6379223a 7b22636f 6465223a 22504b52 222c2263 75727265 6e63796e 616d6522 3a225061 6b697374 616e6920 52757065 65227d7d 2c7b2263 6f756e74 72796e61 6d65223a 22537269 204c616e 6b61222c 22666c61 67223a22 68747470 3a5c2f5c 2f777074 72616666 6963616e 616c797a 65722e69 6e5c2f70 5c2f6465 6d6f315c 2f737269 6c616e6b 612e706e 67222c22 6c616e67 75616765 223a2253 696e6861 6c61222c 22636170 6974616c 223a2253 7269204a 61796177 61726465 6e617075 7261204b 6f747465 222c2263 75727265 6e637922 3a7b2263 6f646522 3a22534b 52222c22 63757272 656e6379 6e616d65 223a2253 7269204c 616e6b61 6e205275 70656522 7d7d2c7b 22636f75 6e747279 6e616d65 223a2243 68696e61 222c2266 6c616722 3a226874 74703a5c 2f5c2f77 70747261 66666963 616e616c
I am using AFNetworking for making URL call.I check this url's in Android.This URL content-type is Application/JSON but in IOS i am getting header content-type text/html.From this URL I am getting sucessful response from URL in JSON format.Please help for solve this issue.
This is my ViewController.m file
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:#"http://wptrafficanalyzer.in/p/demo1/first.php/countries/"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(#"Error: %#", error);
} else {
NSLog(#"%# %#",response);
}
}];
[dataTask resume];
}
Add this code:
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
After this :
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
It is well explained here : Upload an sqlite file
Your server page is returning text/html, but AFURLSessionManager is expecting JSON.
Edit:
As the above solution didn't work out , i found this link containing all possible solution for this error : Request failed: unacceptable content-type: text/html
Image is not uploading in a amazon s3 . I was using the old library all the upload was working fine but for ios 8 i use new sdk and create new conginito id
now i am facing errors. any help will be appreciated
My code is
AWSS3TransferManagerUploadRequest *request = [[AWSS3TransferManagerUploadRequest alloc] init];
request.bucket = #"my bucket name";
request.key = #"my cognitio id";
request.body =[NSURL fileURLWithPath:path];
request.contentType = #"image/png";
[[transferManager upload:request] continueWithExecutor:[BFExecutor mainThreadExecutor]
withBlock:^id(BFTask *task) {
NSLog(#"ckmdkcd dvdsv");
if (task.error) {
if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
switch (task.error.code) {
case AWSS3TransferManagerErrorCancelled:
case AWSS3TransferManagerErrorPaused:
break;
default:
NSLog(#"Error: %#", task.error);
break;
}
} else {
// Unknown error.
NSLog(#"Error: %#", task.error);
}
}
if (task.result) {
AWSS3TransferManagerUploadOutput *uploadOutput = task.result;
// The file uploaded successfully.
NSLog(#"result = %#",task.result);
}
return nil;
}];
I got the following response
AWSiOSSDKv2 [Error] AWSIdentityProvider.m line:185 | __51-[AWSAbstractCognitoIdentityProvider getIdentityId]_block_invoke169 | GetId failed. Error is [Error Domain=NSURLErrorDomain Code=-1003 "The operation couldn’t be completed. (NSURLErrorDomain error -1003.)" UserInfo=0x7f9b987aabf0 {NSErrorFailingURLStringKey=https://cognito-identity.(null).amazonaws.com/, NSErrorFailingURLKey=https://cognito-identity.(null).amazonaws.com/, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSUnderlyingError=0x7f9b9a839480 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1003.)"}]
2015-04-14 08:13:16.326 newtest[6611:172200] AWSiOSSDKv2 [Error] AWSCredentialsProvider.m line:534 | __40-[AWSCognitoCredentialsProvider refresh]_block_invoke350 | Unable to refresh. Error is [Error Domain=NSURLErrorDomain Code=-1003 "The operation couldn’t be completed. (NSURLErrorDomain error -1003.)" UserInfo=0x7f9b987aabf0 {NSErrorFailingURLStringKey=https://cognito-identity.(null).amazonaws.com/, NSErrorFailingURLKey=https://cognito-identity.(null).amazonaws.com/, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSUnderlyingError=0x7f9b9a839480 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1003.)"}]
2015-04-14 08:13:16.328 newtest[6611:172071] ckmdkcd dvdsv
2015-04-14 08:13:16.328 newtest[6611:172071] Error: Error Domain=NSURLErrorDomain Code=-1003 "The operation couldn’t be completed. (NSURLErrorDomain error -1003.)" UserInfo=0x7f9b987aabf0 {NSErrorFailingURLStringKey=https://cognito-identity.(null).amazonaws.com/, NSErrorFailingURLKey=https://cognito-identity.(null).amazonaws.com/, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSUnderlyingError=0x7f9b9a839480 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1003.)"}
I am also setting cognitio id in app delegate.
Based on the fact that you seeing https://cognito-identity.(null).amazonaws.com/ in the error, it would lead me to believe you are not correctly setting the region when creating the AWSCognitoCredentialsProvider. Please double check that you are not setting this to AWSRegionUnknown.
Update 2015-04-17: Here is the list of Region constants. You should set this to the region where your identity pool exists. Currently Amazon Cognito is only available in AWSRegionUSEast1 or AWSRegionEUWest1.
Note, the region of your identity pool has nothing to do the region of other AWS services you may use in your application. You can use an identity pool in AWSRegionUSEast1 to access resources in AWSRegionSAEast1, for instance.
It appears to be working in web:
Web Response Headers:
Connection:keep-alive
Content-Length:394
Content-Type:application/json
Date:Sun, 22 Mar 2015 18:36:06 GMT
Server:nginx/1.6.2
Vary:Accept-Encoding
X-Powered-By:Express
Web Request Headers:
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfaWQiOiI1NDVjYzNjYzQ2N2I3YjAyMDBhMWNkOWEiLCJpYXQiOjE0MjcwNDM3Mzk1NjQsImV4cCI6MTQ5MDExNTczOTU2NH0.Xqm-b12QWcEa6MPXyKa1E8m88hGZI9KfJl7Img3mACU
Connection:keep-alive
Content-Length:225
Content-Type:application/json;charset=UTF-8
Web Request Payload:
{"id":"550f15122cc2708c2d9c65b8","users":["xiruken#gmail.com"],"welcomeMessage":"Hi there. We’ll be using Next24 to keep track of our daily high priority items as a group during this project.","newUser":"xiruken#gmail.com"}
But not working in my native iOS project using objective-C...
Same parameters:
NSDictionary query:
{
id = 550f15122cc2708c2d9c65b8;
newUser = "xiruken#gmail.com";
users = (
"xiruken#gmail.com"
);
welcomeMessage = "Hi there. We will be using Next24 to keep track of our daily high priority items as a group during this project.";
}
AFNetworking code:
-(AFHTTPSessionManager *)sessionManager2{
if(!_sessionManager2){
_sessionManager2 = [[AFHTTPSessionManager alloc] initWithBaseURL: [NSURL URLWithString:API_URL]];
AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init];
[securityPolicy setAllowInvalidCertificates:YES];
[_sessionManager2 setSecurityPolicy:securityPolicy];
_sessionManager2.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingAllowFragments];
NSArray *acceptedTypes = #[#"text/html", #"application/json", #"text/plain"];
_sessionManager2.responseSerializer.acceptableContentTypes = [NSSet setWithArray:acceptedTypes];
//add token
if([Helpers isLoggedIn]){
UserDM *user = [UserDM loadCustomObjectWithKey:DEFAULT_CURRENT_USER];
[self.sessionManager2.requestSerializer setValue:[NSString stringWithFormat:#"Bearer %#", user.accessToken] forHTTPHeaderField:#"Authorization"];
}
}
return _sessionManager2;
}
Using AFJSONResponseSerializer is giving me this error:
2015-03-23 03:28:26.773 Next25[5801:302572] Failed! Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7fdbb252a6e0 {NSDebugDescription=Invalid value around character 0., NSUnderlyingError=0x7fdbb252c410 "Request failed: internal server error (500)"}
I even allowFragments and even set acceptableContentTypes
And changing it to AFHTTPResponseSerializer is giving me a different error:
2015-03-23 03:30:30.797 Next25[5852:303849] Failed! Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo=0x7fb129e4e930 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fb129e36320> { URL: https://myproject.com/api/projects/550f15122cc2708c2d9c65b8/invite_users } { status code: 500, headers {
Connection = "keep-alive";
"Content-Length" = 21;
"Content-Type" = "text/html";
Date = "Sun, 22 Mar 2015 19:26:56 GMT";
Server = "nginx/1.6.2";
Vary = "Accept-Encoding";
"X-Powered-By" = Express;
} }, NSErrorFailingURLKey=https://myproject.com/api/projects/550f15122cc2708c2d9c65b8/invite_users, com.alamofire.serialization.response.error.data=<496e7465 726e616c 20536572 76657220 4572726f 72>, NSLocalizedDescription=Request failed: internal server error (500)}
I have the following code:
- (IBAction)connectToGoogleAnalyticsPressed:(id)sender {
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.attemptSSO = YES;
signIn.clientID = GOOGLE_CLIENT_ID;
signIn.scopes = #[kGTLAuthScopePlusLogin];
signIn.delegate = self;
[signIn authenticate];
}
I get the following error after it's execution:
Error Domain=com.google.HTTPStatus Code=400 "The operation couldn’t be
completed. (com.google.HTTPStatus error 400.)" UserInfo=0x15717010
{data=<7b0a2020 22657272 6f722220 3a202269 6e76616c 69645f72 65717565
7374222c 0a202022 6572726f 725f6465 73637269 7074696f 6e22203a
2022636c 69656e74 5f736563 72657420 6973206d 69737369 6e672e22 0a7d>,
json={
error = "invalid_request";
"error_description" = "client_secret is missing."; }}
I can specify client secret, but [GPPSignIn sharedInstance] doesn't have such property!
Google documentation says nothing about this case.
How to avoid the error above?
The problem was with wrong Client ID - it was for web application, not for installed application.