目标C中的Web服务RESTFUL:LINK请求

时间:2015-07-07 10:02:17

标签: ios objective-c web-services

目前我正在使用我的应用中的网络服务,我们已经实现了一个LINK网址,以便...链接我们数据库中的两个实体。

但它似乎不适用于这种请求,因为当我调用url时,我没有收到任何响应。 (通常我必须收到一个布尔值,成功为true或false,带有错误信息(如果没有问题,则必须收到)。

关于此类请求的任何想法?

我的功能:

-(void)LINKWithNoParameters: (NSString*)path{
    //associate the url api path with the requested path
    NSURL *url = [NSURL URLWithString:[CV_API_URL stringByAppendingString:path]];

//create the request with LINK method & json content
NSMutableURLRequest *rq = [NSMutableURLRequest requestWithURL:url];
[rq setHTTPMethod:@"LINK"];
[rq setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

NSError *requestError;
NSURLResponse *urlResponse = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:rq returningResponse:&urlResponse error:&requestError];

NSLog(@"\n\n-----------------\n Sending this URL in %@: %@ \n-----------------\n\n", rq.HTTPMethod,url);

if ([data length] > 0 && requestError == nil){
    //NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"\n\n-----------------\n RECEIVED DATA : \n-----------------\n\n ");
    [self receivedData:data forRequestComponent:path];
}
else if ([data length] == 0 && requestError == nil)
    NSLog(@"empty reply");
else if (requestError != nil)
    NSLog(@"error : %@", requestError);
}

1 个答案:

答案 0 :(得分:0)

为什么你在这里使用LINK [rq setHTTPMethod:@"LINK"];

试试这个

 NSURL *url = [NSURL URLWithString:[CV_API_URL stringByAppendingString:path]];

    //create the request with LINK method & json content
    NSMutableURLRequest *rq = [NSMutableURLRequest requestWithURL:url];
    [rq setHTTPMethod:@"POST"];
    [rq setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    NSError *requestError;
    NSURLResponse *urlResponse = nil;
    NSData *data = [NSURLConnection sendSynchronousRequest:rq returningResponse:&urlResponse error:&requestError];

    NSLog(@"\n\n-----------------\n Sending this URL in %@: %@ \n-----------------\n\n", rq.HTTPMethod,url);