AFNetworking
프레임 워크를 처음 사용하고 있습니다. 내가 JSON 응답을 얻기 위해 서버에 JSON 요청을 보내려고, 그래서 나는이 같은 시도 :JSON 요청 전달 방법
Error Domain=com.alamofire.networking.error Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x7b58030 {NSErrorFailingURLKey=http://data.mycity.gov/api/views/INLINE/rows.json?method=index, NSLocalizedDescription=Expected status code in (200-299), got 400}
:이 오류 설명과 함께,
NSURL *url = [NSURL URLWithString:@"http://data.mycity.gov/api/views/INLINE/rows.json?method=index"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:[NSString stringWithFormat:@"application/json"] forHTTPHeaderField:@"Content-Type"];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Success");
} failure:^(NSURLRequest* req,NSHTTPURLResponse *req2, NSError *error,id mex) {
NSLog(@"Failed");
NSLog(@"%@",[error description]);
}];
[operation start];
그래서 난 항상 실패 블록으로 내 자신을 찾기
아이디어가 있으십니까? 내가 놓친 게 있니?
Malek, JSON 요청이 무슨 뜻인지 모르겠다 - 이것은 HTTP 요청이며 일부 요청 매개 변수가 누락되었을 수 있습니다. API에서 데이터를 요청하고 있습니까? –
Hello Shai, 예, HTTP 요청이지만 JSON 응답을 받으려면 – Luca