I have simple API developed in Slim, which is stored in Online Server. It works fine when I check it from browser, but when I retrieve it from Iphone app, it show me the following error:
PeopleAlsoAsk[12607:2219389] Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 500" UserInfo={NSLocalizedRecoverySuggestion="this is index pagpe, Specific questions are retrieved successfully", NSErrorFailingURLKey=http://upvc.pk/test2/public/, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x608000001060> { URL: http://upvc.pk/test2/public/ }, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x60800003d6c0> { URL: http://upvc.pk/test2/public/ } { status code: 500, headers {
"Accept-Ranges" = bytes;
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 81;
Date = "Wed, 26 Apr 2017 12:34:31 GMT";
Server = LiteSpeed;
Vary = "Accept-Encoding";
"X-Powered-By" = "PHP/7.0.17";
} }, NSLocalizedDescription=Expected status code in (200-299), got 500}
2017-04-26 17:34:31.462 PeopleAlsoAsk[12607:2219389] Error function called
I tried a lot, but all in vain. If any one faced this problem, or know about this, then please guide me in this. Thanks in advance.
My code is given below
public/index.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App;
//Questions Routes
require '../src/routes/questions.php';
$app->run();
routes/questions.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
//Get All Questions
$app->get('/api/questions', function(Request $request, Response $response){
$questions = "All questions are retrieved successfully";
echo json_encode($questions);
});
// Get specific Questions
$app->get('/api/questions/{app_id}', function(Request $request, Response $response){
$questions = "Specific questions are retrieved successfully";
echo json_encode($questions);
});
You should put your iOS code here.
From your Slim, I would place:
$app->status($status_code);
In your response code, you can add this function to give all client response:
function echoResponse($status_code, $response) {
$app = \Slim\Slim::getInstance();
// Http response code
$app->status($status_code);
// setting response content type to json
$app->contentType('application/json');
echo json_encode($response);
}
Usage very simple:
echoResponse(200, "your response");
From iOS point of view, hard to say something without the code.
Related
I have been able to authenticate with the Pinterest API on both the javascript and Android SDK. On iOS, I've triple-checked all of my settings to make sure I've configured everything according to the documentation.
However, when I log in through iOS, I am taken to the Pinterest app to authorize and all looks good. However, when Pinterest passes me back to my app, I am getting the following login error:
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unauthorized (401)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x17403dea0> { URL: https://api.pinterest.com/v1/oauth/inspect?access_token=AYalMni-yTq5Y0UihwETrFxZpzL5FK2tXvfmkbhDyJ_OP8BGeQAAAAA&token=AYalMni-yTq5Y0UihwETrFxZpzL5FK2tXvfmkbhDyJ_OP8BGeQAAAAA } { status code: 401, headers {
Age = 0;
"Cache-Control" = private;
Connection = "keep-alive";
"Content-Length" = 177;
"Content-Type" = "application/json";
Date = "Mon, 20 Mar 2017 19:21:15 GMT";
"Pinterest-Generated-By" = "devplatform-devapi-prod-0a01239b";
"Pinterest-Version" = 918ef75;
"X-Content-Type-Options" = nosniff;
"X-Pinterest-RID" = 280542321780;
} }, NSErrorFailingURLKey=https://api.pinterest.com/v1/oauth/inspect?access_token=AYalMni-yTq5Y0UihwETrFxZpzL5FK2tXvfmkbhDyJ_OP8BGeQAAAAA&token=AYalMni-yTq5Y0UihwETrFxZpzL5FK2tXvfmkbhDyJ_OP8BGeQAAAAA, com.alamofire.serialization.response.error.data=<7b227374 61747573 223a2022 6661696c 75726522 2c202263 6f646522 3a20332c 2022686f 7374223a 20226465 76706c61 74666f72 6d2d6465 76617069 2d70726f 642d3061 30313233 3962222c 20226765 6e657261 7465645f 6174223a 20224d6f 6e2c2032 30204d61 72203230 31372031 393a3231 3a313520 2b303030 30222c20 226d6573 73616765 223a2022 41757468 6f72697a 6174696f 6e206661 696c6564 2e222c20 22646174 61223a20 6e756c6c 7d>, NSLocalizedDescription=Request failed: unauthorized (401)}
I tried taking the access token referred to in the error response and using the token debugger on the Pinterest developer site to check it, but when I did so I got the message "An error occurred. Please try again."
So, I'm stumped. It seems to me that the access token that's being generated on iOS login is being seen as invalid by Pinterest, but I don't know how to fix that.
Do you have any thoughts on what can be done to resolve this?
I use AFNetworking(2.6.3). I try use Charles map local response for one request. After lot of times, when I disable this map, I also only get local response, can't get online response.
The response from AFNetworking:
<NSHTTPURLResponse: 0x17102e820> { URL: https://api.xiangrikui.com/bxr/apps/activities } { status code: 200, headers {
Connection = "Keep-alive";
"Content-Length" = 604;
"Content-Type" = "application/json";
"X-Charles-Map-Local" = "/Users/linliling/Desktop/???app?????/poster1.json";
} }
I have faced something similar, but the connection said that it was closed. Try with another proxy program like Burp. It's not fancy as Charles but it gets the job done.
Also if you could post the response you see in Charles it will be useful to better understand the issue.
Im getting this error while posting image to Pinterest
Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unauthorized (401)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x144603bd0> { URL: https://api.pinterest.com/v1/pins/ } { status code: 401, headers {
"Accept-Ranges" = bytes;
"Cache-Control" = private;
Connection = close;
"Content-Length" = 177;
"Content-Type" = "application/json";
Date = "Sun, 10 Jul 2016 19:38:00 GMT";
"Pinterest-Generated-By" = "devplatform-devapi-prod-de3d740a";
"Pinterest-Version" = bcdafd3;
Server = nginx;
"X-Content-Type-Options" = nosniff;
"X-Pinterest-RID" = 480720869025;
"X-Varnish" = 2958547338;
} }, NSErrorFailingURLKey=https://api.pinterest.com/v1/pins/, com.alamofire.serialization.response.error.data=<7b227374 61747573 223a2022 6661696c 75726522 2c202263 6f646522 3a20332c 2022686f 7374223a 20226465 76706c61 74666f72 6d2d6465 76617069 2d70726f 642d6465 33643734 3061222c 20226765 6e657261 7465645f 6174223a 20225375 6e2c2031 30204a75 6c203230 31362031 393a3338 3a303020 2b303030 30222c20 226d6573 73616765 223a2022 41757468 6f72697a 6174696f 6e206661 696c6564 2e222c20 22646174 61223a20 6e756c6c 7d>, NSLocalizedDescription=Request failed: unauthorized (401)}
Here is my code:
PDKClient.sharedInstance().createPinWithImage(image, link: NSURL(string:"http://domain"), onBoard: "MyBoard", description: caption, progress: {percent in
print(percent)
}, withSuccess: {PDKResponseObject in
print("ok")
print(PDKResponseObject.boards())
}, andFailure: {error in
print(error)
})
Error 401 means one of the following.
1.Authentication failed.
2.Authorization failed.
3.You are not permitted to access that resource.
Double check your permissions, check your session token expired or not.
So I think that there is nothing wrong with your code, or the request. It's something with the permissions you have in your Pinterest app.
Try changing the request URL from http to https.
Check the parameters you sending to Pinterest, check whether the parameter names are correct or not, as specified in Pinterest documentation. Also those parameters has the proper type of data, I mean do not pass String in the place of Integer value.
.
I receive this error when I tried to signup an account with the app im building. May I know what does this error means? Thank you!
BaseNetworkManager.m:164 Error Domain=AFNetworkingErrorDomain Code=-1011
"Expected status code in (200-299), got 500" UserInfo=0x16d30560
{NSLocalizedRecoverySuggestion=meta http-equiv="refresh" content="0;
url =websitelink.error.html"
AFNetworkingOperationFailingURLRequestErrorKey=NSMutableURLRequest: 0x16670d80> { URL: mywebsite/users.json }, NSErrorFailingURLKey=h mywebsite.com/users.json, NSLocalizedDescription=Expected status code in (200-299), got 500, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x1669fe20> { URL: mywebsite.com/users.json } { status code: 500, headers {
Connection = "keep-alive";
"Content-Length" = 690;
"Content-Type" = "text/html; charset=utf-8";
Date = "Fri, 01 May 2015 12:37:44 GMT";
Server = Cowboy;
Status = "500 Internal Server Error";
Via = "1.1 vegur";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = "tyud";
"X-Runtime" = "5.087065"; } }}
2015-05-01 20:37:45.002 appname[1677:60b] <BaseNetworkManager.m:165> (null)
The server is telling you
500 Internal Server Error
this means that the server has a problem that is not your fault. (unless you are the one who is responsible for the server.)
HTTP 200..299 means "ok"
HTTP 300..399 means "look somewhere else"
HTTP 400..499 means "there is a problem with your request." for example 404=file not found, 403=forbidden, etc.
HTTP 500..599 means "the server has a problem / is misconfigured"
see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more info.
I'm updating the example Todo app from Microsoft Azure Mobile Services for iOS to use Table Storage instead of the default MSSQL backend. At the moment, when I try to insert a new item, I am getting the following error in the client:
2014-11-22 11:06:44.895 xxx[6942:869598] ERROR Error Domain=com.Microsoft.WindowsAzureMobileServices.ErrorDomain Code=-1201 "The server did not return the expected item." UserInfo=0x7a6b1040 {NSLocalizedDescription=The server did not return the expected item., com.Microsoft.WindowsAzureMobileServices.ErrorResponseKey=<NSHTTPURLResponse: 0x7a764cc0> { URL: https://xxx.azure-mobile.net/tables/TodoItem } { status code: 200, headers {
"Cache-Control" = "no-cache";
"Content-Encoding" = gzip;
"Content-Length" = 126;
"Content-Type" = "application/json";
Date = "Sat, 22 Nov 2014 19:06:44 GMT";
Server = "Microsoft-IIS/8.0";
Vary = "Accept-Encoding";
"X-Powered-By" = "ASP.NET";
"x-zumo-version" = "Zumo.master.0.1.6.4100.Runtime";
} }, com.Microsoft.WindowsAzureMobileServices.ErrorRequestKey=<NSMutableURLRequest: 0x7a7797a0> { URL: https://xxx.azure-mobile.net/tables/TodoItem }}
I have not changed the client code. The docs at https://github.com/Azure/azure-mobile-services/blob/master/sdk/iOS/src/MSJSONSerializer.m suggest that this error is an 'errorForExpectedItem' error, and it gets thrown in itemFromData:withOriginalItem:ensureDictionary:orError:.
This error started happening as I was trying to get the todoitem.read.js script to work; I am so far unable to get usable entities back from that script. Here's my todoitem.read.js as it now stands:
var azure = require('azure-storage');
var tableSvc = azure.createTableService();
function read(query, user, request) {
query = new azure.TableQuery()
.select()
.where('PartitionKey eq ?', 'learningazure');
console.log('query: ', query);
tableSvc.queryEntities('TodoItem',query, null, function(error, result, response) {
if(!error) {
// query was successful
// add the count to the response dictionary
response.count = response.body.value.length;
response.results = result.entries;
request.respond(200, response);
} else {
console.log('Error calling read()');
console.log(error);
}
});
}
Any suggestions?
Derp. My error: in todoitem.insert.js, in the insert() function, I was never calling request.respond().
Now the node.js code is returning data, but it's still not showing up in the iOS client. More reading required.