Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9149891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:32:19+00:00 2026-06-17T11:32:19+00:00

I am a beginner to iOS. I have a simple web service that retrieves

  • 0

I am a beginner to iOS. I have a simple web service that retrieves data from a table and sends out the results in JSON. I am trying to communicate with that web service from iOS to receive the JSON response but facing issues. This is the error i receive:

Request Failed with Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected     content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html" UserInfo=0x7598e70

Here are my code snippets:

PHP Web Service:

$stmt = "SELECT STORE_TYPE, STORE_NAME FROM STORE WHERE STORE_ZIP = $zip";
$result = mysqli_query($this->databaseconnection, $stmt);  
$storelist = array();
$store = array();
$jsondata;
while ($row = mysqli_fetch_assoc($result)) {
  $store['STORE_TYPE'] = $row['STORE_TYPE'];
  $store['STORE_NAME'] = $row['STORE_NAME'];
  array_push($storelist,$store);
}
$jsondata = json_encode($storelist);
echo $jsondata;

I am getting the following result when i execute my php form the browser:

[{"STORE_TYPE":"GROCERY","STORE_NAME":"Walmart"},{"STORE_TYPE":"BAKERY","STORE_NAME":"Lanes Bakery"},{"STORE_TYPE":"GROCERY","STORE_NAME":"Copps"}]

iOS Code Snippet to communicate with the Web Service:

NSURL *url = [NSURL URLWithString:@"http://localhost/~Sandeep/store/store.php?rquest=getstores&zip=53715"];

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation  JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSLog(@"%@", JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
    NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
[operation start];

I looked at a lot of tutorials and they all say that performing a ‘json_encode’ on an array in php encodes the data in JSON format and ‘echo’ of that is the way to go send the encoded JSON as a response. For some reason my iOS is not seeing that as JSON. I am not sure what I am missing/doing wrong here.

I really appreciate your inputs on this.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:32:20+00:00Added an answer on June 17, 2026 at 11:32 am

    You need to set the correct content type(use header), the error lists the acceptable types though you should use application/json

    $stmt = "SELECT STORE_TYPE, STORE_NAME FROM STORE WHERE STORE_ZIP = $zip";
    $result = mysqli_query($this->databaseconnection, $stmt);  
    $storelist = array();
    $store = array();
    $jsondata;
    while ($row = mysqli_fetch_assoc($result)) {
      $store['STORE_TYPE'] = $row['STORE_TYPE'];
      $store['STORE_NAME'] = $row['STORE_NAME'];
      array_push($storelist,$store);
    }
    $jsondata = json_encode($storelist);
    header('Content-Type: application/json');
    echo $jsondata;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Hi I'm studying IOS programing through example code from the web. I found that
Beginner iOS dev here. I have a problem in my array. Im making an
Beginner in Android development. My code crashes. I have made a simple Java method
I'm a beginner in iOS development and I have to put in the same
I'm a beginner in iOS and need some leads to do something that don't
I am a beginner ios developer.I am tryin to develop a simple jokes app.Is
iOS beginner here. I have the following code: [facebook authorize:nil delegate:self]; NSString *string1=[facebook accessToken];
I am a beginner in iOS development. I have got some understanding on provisioning
*beginner iOS programmer, please explain with patience suppose i have 2 classes - Foo,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.