I dont know how to where i should start from.
So, pleaes forgive me if I'm asking wrong question.
I have an iOS app. The app request to an API of CentOS server which using FuelPHP to get list of data. Also, we are using CDN to cache the data (Azure -Verizon)
When I get respond header, I saw that :
Access-Control-Allow-Headers" = ": X-Requested-With";
"Access-Control-Allow-Methods" = ": post, get, origins";
"Access-Control-Allow-Origin" = ": *";
"Cache-Control" = "no-cache, must-revalidate";
Connection = close;
"Content-Type" = "application/json";
Date = "Mon, 13 Mar 2017 07:13:01 GMT";
Expires = "Sat, 26 Jul 1997 05:00:00 GMT";
Pragma = "no-cache";
Server = "Apache/2.2.15 (CentOS)";
"Transfer-Encoding" = Identity;
"X-Powered-By" = "PHP/5.5.32
What should I do to make Cache-Control become max-age=xxx?
what I want is to cache the data via CDN of window Aruze Verizon.
Please help, If my question is not clear, please guide me, i will provide mor information.
Related
We are experiencing an issue downloading file, when we activate airplane mode.
We are using the following Manager configuration:
let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(self.sessionIdentifier)
configuration.HTTPMaximumConnectionsPerHost = 1
let manager = Alamofire.Manager(configuration: configuration)
The expected behaviour is that when you activate the airplane mode, the response handler is not called and the download is still active and waiting for the internet connection to be active again. But the response is called and we get the following information:
Error:
Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL}
Data:
nil
Response:
status code: 200, headers {
"Accept-Ranges" = bytes;
"Cache-Control" = "max-age=604800";
"Content-Length" = 138310665;
"Content-Type" = "video/mp4";
Date = "Thu, 20 Oct 2016 13:09:19 GMT";
Etag = "\"3168233889\"";
Expires = "Thu, 27 Oct 2016 13:09:19 GMT";
"Last-Modified" = "Fri, 25 Sep 2015 09:38:30 GMT";
Server = "ECAcc (fcn/40BD)";
"X-Cache" = HIT;
And the original request
Notice that the error does not contain, even resume data, which I think it should.
And also this is not the case when we test it in the simulator and stop the internet connection.
Any help will be much appreciated!
*
Note: There are several links on this topic but it didn't work for me,
So I have to post the new one here.
*
Basically I'm trying to show the UIProgressView to show the data being fetched from the web service. Now problem is that I'm getting the expectedContentLength for almost all the service that I call from my application and the response headers contains the Content-Length. But for one of the web service's response it doesn't return the expectedContentLength, instead always returns -1.
Following are the response headers that I get for two different web service response :
- Response header for which I get the content length.(Data from service is not huge)
{
Connection = "Keep-Alive";
"Content-Length" = 2689;
"Content-Type" = "application/json";
Date = "Tue, 23 Jun 2015 08:19:04 GMT";
"Keep-Alive" = "timeout=5, max=98";
Server = "Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15";
"X-Powered-By" = "PHP/5.5.15";
}
- Response header for which I don't get the content length. (Response contains the huge data, no files to be downloaded just JSON data)
{
Connection = "Keep-Alive";
"Content-Type" = "application/json";
Date = "Tue, 23 Jun 2015 08:12:34 GMT";
"Keep-Alive" = "timeout=5, max=97";
Server = "Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15";
"Transfer-Encoding" = Identity;
"X-Powered-By" = "PHP/5.5.15";
}
The Above service response contains huge data. When tested the response on Advanced rest client chrome's extension It gives following response header with "Transfer-Encoding" = chunked;.
Date: Tue, 23 Jun 2015 12:01:20 GMT
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15
X-Powered-By: PHP/5.5.15
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json
I used following links, but none of them helped me:
Link1 , Link2 , Link3
Please help me.
Thanks!
Updated code:
After setting the Content-Lenth header on server side I got the valid response with Content-Length header on Advanced rest client chrome's extension.
Date: Wed, 24 Jun 2015 05:25:48 GMT
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15
X-Powered-By: PHP/5.5.15
Content-Length: 1272347
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json
But on client side (i.e in iOS Application) I still didn't get the Content-Lenth header so that I can get the expectedContentLength value.
I still get "Transfer-Encoding" = Identity; in the response header on my side.
I have also set the Accept-Encoding header in the request as follows :
[req setValue:#"identity;q=0" forHTTPHeaderField:#"Accept-Encoding"];
Is there anything more to be done on either side(server/client).
I don't know how one gets the content length added at the server side - I had problems with this before, and in one case I had a similar situation as yours - the content length was visible by dumping all headers, but iOS didn't hand it to me in the delegate method. The standard way to get it is via:
- (void)connection:(NSURLConnection *)conn didReceiveResponse:(NSURLResponse *)response
{
...
NSUInteger responseLength = response.expectedContentLength == NSURLResponseUnknownLength ? 1024 : (NSUInteger)response.expectedContentLength;
I actually entered a bug on this: rdar://15605995 "HTTP Get response is 200 but response.expectedContentLength = -1 even when a Content-Length is found in the headers"
2014-01-08 18:49:36.966 DB_Lookup[36824:3f07] YIKES:LEN=22162 {
"Cache-Control" = "must-revalidate";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Length" = 22162;
"Content-Type" = "text/html; charset=UTF-8";
Date = "Wed, 08 Jan 2014 23:49:09 GMT";
Expires = 0;
"Front-End-Https" = on;
Pragma = "no-cache";
Server = "nginx/1.2.4";
"Strict-Transport-Security" = "max-age=2592000";
Vary = "Accept-Encoding";
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = SAMEORIGIN;
"X-Powered-By" = <Company>;
"X-<Company>-Server" = "<private>";
"X-XSS-Protection" = "1; mode=block";
}
for this code:
if(response.expectedContentLength == NSURLResponseUnknownLength) {
id len = httpResponse.allHeaderFields[#"Content-Length"];
if(len) {
responseLength = [len integerValue];
}
NSLog(#"YIKES:LEN=%# %#", len, httpResponse.allHeaderFields);
}
This is going to be really hard for me to special case. I'm accessing an internal company data base, I have to use name/password first, then get a code to my phone (which I later enter) to get in. Is there other info I could grab to help you? How can it be that the content length is clearly there in the header, but you don't see it and return it to me?
Apple closed my bug, saying "Works as Expected". Really!?!?!?!?!?!?!
[I don't know if NSURLSession fixed it or not.]
EDIT: I should have added that in the past, other sites I connected to DID result in a properly set 'expectedContentLength'.
I'm working my way through the relevant Quickblox modules starting with users. I can authenticate an application and register a new account and login.
I tried to login with a Facebook account using
[QBRequest logInWithSocialProvider:#"facebook" scope:#[] successBlock:[self successBlock] errorBlock:[self errorBlock]];
but nothing happens. When I try it with the sample code, I get a popup dialog. The API is so well hidden, I can't troubleshoot the popup. What am I missing?
The console output:
Request URL:https://api.quickblox.com/login.json
Request method: POST
Request parameters:{
provider = facebook;
}
Request headers: {
"Content-Type" = "application/json";
"QB-SDK" = "iOS 2.0.9";
"QB-Token" = XXXXXXXXXXXXXXXXXX;
"QuickBlox-REST-API-Version" = "0.1.1";
}
__65-[QBHTTPConnection generateRequestOperation:forPath:usingMethod:]_block_invoke126 -> Redirecting, request: https://www.facebook.com/dialog/oauth?response_type=code&client_id=XXXXXXXXXXX&redirect_uri=http%3A%2F%2Fapi.quickblox.com%2Fauth%2Ffacebook%2Fcallback&state=XXXXXXXXXXX.users.json&display=touch&scope=email, redirectResponse: https://graph.facebook.com/oauth/authorize?response_type=code&client_id=XXXXXXX&redirect_uri=http%3A%2F%2Fapi.quickblox.com%2Fauth%2Ffacebook%2Fcallback&state=XXXXXXXXXXXX.users.json&display=touch&scope=email
__65-[QBHTTPConnection generateRequestOperation:forPath:usingMethod:]_block_invoke126 -> Redirecting, request: https://m.facebook.com/v2.1/dialog/oauth?redirect_uri=http%3A%2F%2Fapi.quickblox.com%2Fauth%2Ffacebook%2Fcallback&state=XXXXXXXXXXX.users.json&scope=email&response_type=code&client_id=XXXXXXXXXXXXXXX, redirectResponse: https://www.facebook.com/dialog/oauth?response_type=code&client_id=365974270237542&redirect_uri=http%3A%2F%2Fapi.quickblox.com%2Fauth%2Ffacebook%2Fcallback&state=XXXXXXXXXX.users.json&display=touch&scope=email
__65-[QBHTTPConnection generateRequestOperation:forPath:usingMethod:]_block_invoke126 -> Redirecting, request: https://m.facebook.com/login.php?skip_api_login=1&api_key=365974270237542&signed_next=1&next=https%3A%2F%2Fm.facebook.com%2Fv2.1%2Fdialog%2Foauth%3Fredirect_uri%3Dhttp%253A%252F%252Fapi.quickblox.com%252Fauth%252Ffacebook%252Fcallback%26state%XXXXXXXXXXXX.users.json%26scope%3Demail%26response_type%3Dcode%26client_id%3D365974270237542%26ret%3Dlogin&cancel_uri=http%3A%2F%2Fapi.quickblox.com%2Fauth%2Ffacebook%2Fcallback%3Ferror%3Daccess_denied%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%26state%XXXXXXXXXXXXXXXX.users.json%23_%3D_&display=touch&_rdr, redirectResponse: https://m.facebook.com/v2.1/dialog/oauth?redirect_uri=http%3A%2F%2Fapi.quickblox.com%2Fauth%2Ffacebook%2Fcallback&state=XXXXXXXXXXXX.users.json&scope=email&response_type=code&client_id=XXXXXXXXXXXXXX
Response headers: {
"Cache-Control" = "private, no-cache, no-store, must-revalidate";
"Content-Encoding" = gzip;
"Content-Type" = "text/html; charset=utf-8";
Date = "Mon, 20 Oct 2014 19:39:49 GMT";
Expires = "Sat, 01 Jan 2000 00:00:00 GMT";
Pragma = "no-cache";
"Set-Cookie" = "datr=IFpFVEOSkGoM49QHhNpqt37f; expires=Wed, 19-Oct-2016 19:39:49 GMT; Max-Age=63072000; path=/; domain=.facebook.com; httponly, reg_ext_ref=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=.facebook.com, reg_fb_ref=https%3A%2F%2Fm.facebook.com%2Flogin.php%3Fskip_api_login%3D1%26api_key%XXXXXXXXXXX%26signed_next%3D1%26next%3Dhttps%253A%252F%252Fm.facebook.com%252Fv2.1%252Fdialog%252Foauth%253Fredirect_uri%253Dhttp%25253A%25252F%25252Fapi.quickblox.com%25252Fauth%25252Ffacebook%25252Fcallback%2526state%253De1d84aXXXXXX.users.json%2526scope%253Demail%2526response_type%253Dcode%2526client_id%253D365974270237542%2526ret%253Dlogin%26cancel_uri%3Dhttp%253A%252F%252Fapi.quickblox.com%252Fauth%252Ffacebook%252Fcallback%253Ferror%253Daccess_denied%2526error_code%253D200%2526error_description%253DPermissions%252Berror%2526error_reason%253Duser_denied%2526state%253De1d84ad000164XXXXXXXXXb40ab6b321.users.json%2523_%253D_%26display%3Dtouch; path=/; domain=.facebook.com, m_ts=1413833989; path=/; domain=.facebook.com; httponly";
p3p = "CP=\"Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p\"";
"x-content-type-options" = nosniff;
"x-fb-debug" = "BImF8RRsnETruM0QYD0fBV3KszW1T4VMWl1Btxl3//5CcsLSJgLDG9Sz99coS+qYlDsx53SKC6pvpNt+WVzhFA==";
"x-frame-options" = DENY;
"x-xss-protection" = 0;
}
Response JSON: (null)
Well, now I feel silly. I kept working on the app and then I discovered that the dialog screen actually popped UNDER the top viewController.
I haven't changed anything in my app and my code seems to generate the proper URL with access token attached, but I am getting a 400 error bad request for the past day. It doesn't seem as if Instagram has changed the endpoint. Can someone help me decipher the error log to see if there is any usable info here to help me debug? Access Token x'd out.
Failure Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)"
UserInfo=0x9261450 {NSErrorFailingURLKey=https://api.instagram.com/v1/locations/search?lat=37.785834&lng=-122.406417&distance=50&access_token=XXXX, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x92627d0> { URL: https://api.instagram.com/v1/locations/search?lat=37.785834&lng=-122.406417&distance=50&access_token=XXXX }
{ status code: 400, headers {
"Cache-Control" = "private, no-cache, no-store, must-revalidate";
Connection = "keep-alive";
"Content-Language" = en;
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 26 Aug 2014 05:19:53 GMT";
Expires = "Sat, 01 Jan 2000 00:00:00 GMT";
Pragma = "no-cache";
Server = nginx;
"Set-Cookie" = "csrftoken=26b1980509fc8303e630689c2d483074; expires=Tue, 25-Aug-2015 05:19:53 GMT; Max-Age=31449600; Path=/, ccode=US; Path=/";
"Transfer-Encoding" = Identity;
Vary = "Cookie, Accept-Language";
"X-Ratelimit-Limit" = 5000;
"X-Ratelimit-Remaining" = 4999;
} }, NSLocalizedDescription=Request failed: bad request (400)}
A few time ago I've developed an iOS app with MGTwitterEngine and XML parsing option.
Since Twitter updated the API to 1.1, seems to be that all messages must be called with JSON format.
After a long nightmare to integrate YAJL library with MGTwitterEngine, my program makes a Succeeded Request but the statusesReceived delegate method is not fired.
I've checked if the delegated is properly assigned, and everything is correct. After launch the HTTP request I get the response OK but not any message.
Here an example of the call I made:
INFO -> Twitter URL: https://api.twitter.com/1.1/statuses/user_timeline.json?since_id=1&screen_name=CFarmaceutico&count=50
And here the response:
MGTwitterEngine: (200) [no error]:
{
"Cache-Control" = "no-cache, no-store, must-revalidate, pre-check=0, post-check=0";
"Content-Encoding" = gzip;
"Content-Length" = 10778;
"Content-Type" = "application/json;charset=utf-8";
Date = "Thu, 28 Nov 2013 11:57:33 GMT";
Expires = "Tue, 31 Mar 1981 05:00:00 GMT";
"Last-Modified" = "Thu, 28 Nov 2013 11:57:33 GMT";
Pragma = "no-cache";
Server = tfe;
"Set-Cookie" = "lang=es, guest_id=v1%3A138563985309026395; Domain=.twitter.com; Path=/; Expires=Sat, 28-Nov-2015 11:57:33 UTC";
Status = "200 OK";
"Strict-Transport-Security" = "max-age=631138519";
"x-access-level" = "read-write-directmessages";
"x-frame-options" = SAMEORIGIN;
"x-rate-limit-limit" = 180;
"x-rate-limit-remaining" = 166;
"x-rate-limit-reset" = 1385639983;
"x-transaction" = da0b638eef7ffe43;
"x-xss-protection" = "1; mode=block";
}
2013-11-28 12:57:34.025 Otsuka On[60073:a0b] Request Suceeded: 59CA5086-8AA9-4632-978B-2B9F2334D704
But the statusesReceived method is not called anymore.
Any idea?
Thanks.
no idea - but MGTwitterEngine does not support API 1.1, and when API 1.1 was released, we tried hard to get MGTwitterEngine working - and failed. Eventually we converted our app to FHSTwitterEngine - and it works fine since then. It was relatively straightforward process so I would strongly recommend you to do the same. It will take you less time than fixing bugs in MGTwitterEngine.