我有一个UITextField,当我在UITextField中写东西并按下更新按钮时,我想更新我的服务器,我使用了AFNetworking,但是我有一个错误:
Domain=com.alamofire.error.serialization.response Code=-1011
"Request failed: internal server error (500)
{ status code: 500, headers {
"Access-Control-Allow-Headers" = "Origin, X-Requested-With, Content-Type, Accept";
"Access-Control-Allow-Methods" = "OPTIONS,GET,POST,PUT,DELETE";
"Access-Control-Allow-Origin" = "*";
Connection = "keep-alive";
"Content-Type" = "text/plain";
Date = "Thu, 24 Jul 2014 00:41:56 GMT";
Server = Cowboy;
"Transfer-Encoding" = Identity;
Via = "1.1 vegur";
"X-Powered-By" = Express;
} }, NSLocalizedDescription=Request failed: internal server error (500)}
Run Code Online (Sandbox Code Playgroud)
这是我的更新按钮代码:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSDictionary *params = @ …Run Code Online (Sandbox Code Playgroud) 我在服务器上有json文件,其余的APLI,我想与服务器通信,现在我用这个方法连接到服务器并在我的viewdidload方法中调用它,我的问题是,最好的方法是什么,可以我用单身人士?如果是的应该怎么样?提前致谢!
感谢答案部分中的任何代码建议.
- (void)viewDidLoad
{
[super viewDidLoad];
_mapView.showsUserLocation = YES;
_mapView.delegate = self;
[self fetchData];
}
-(void)fetchData
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:BASED_URL]];
[request setHTTPMethod:@"GET"];
[request setValue:@"/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
NSURLResponse *response;
NSData *GETReply = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:nil];
NSString *theReply = [[NSString alloc] initWithBytes:[GETReply bytes] length:[GETReply
length] encoding: NSASCIIStringEncoding];
CLLocationCoordinate2D location;
NSMutableArray *newAnnotations = [NSMutableArray array];
NSError *error;
NSArray *array = [NSJSONSerialization JSONObjectWithData:GETReply
options:0
error:&error];
if (error != nil)
{
// handle the error
}
for (NSDictionary …Run Code Online (Sandbox Code Playgroud)