iphone应用程序中的Web服务问题

时间:2011-05-21 00:44:46

标签: iphone cocoa rest service

我正在尝试为我的iphone应用程序连接到一个Web服务(从来没有想到它会变得如此困难......)但是我收到以下错误:无法提供列出的媒体类型Accept标头,找不到POST的资源方法,返回405 with Allow header。

完整回复如下: CLIENT.MethodNotAllowed无法提供Accept标头中列出的媒体类型,找不到POST的资源方法,返回405 with Allow标头。

这意味着什么?我不知道从哪里开始尝试多种不同的东西。这是我正在使用的代码:

   NSString *soapMsg = 
    [NSString stringWithFormat:
     @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"
     "<soap:Body>"
     "<standardization inputFormat=\"docdb\" outputFormat=\"epodoc\" xmlns=\"http://abc.mycompany.org\">"
     "<input>"
     "<publication xmlns=\"http://www.mycompany.org/exchange\">"
     "<document-id><country>MD</country>"
     "<number>20050130</number>"
     "<mytype>A</mytype>"
     "<date>20050130</date>"
     "</document-id></publication></input></standardization></soap:Body></soap:Envelope>"];

    NSLog(@"%@", soapMsg);

    NSURL *url = [NSURL URLWithString:
                  @"http://abc.mycompany.org/2.6.2/rest-services/myservice"];
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

    //set various headers
    NSString *msgLength = [NSString stringWithFormat:@"%d",
                           [soapMsg length]];
    [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

    [req addValue:msgLength forHTTPHeaderField:@"Content-Length"];

    //set http methods and body
    [req setHTTPMethod:@"POST"];
    [req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

    conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];

    if (conn) {
        webData = [[NSMutableData data] retain];
    }

0 个答案:

没有答案