2012-05-02 2 views
2

私は1つの方法の書き込みがあります。

-(id)postAndParseJson:(NSMutableDictionary *)theDictionary action:(NSString *)action type:(NSString *)myType { 

    NSString *newJSON = [theDictionary JSONRepresentation]; 
    NSLog(@"what to send: %@", newJSON); 

    NSURL *url = [NSURL URLWithString:@"http://api.uat.ushi.cn/user/getProfile?user_id=3"]; 
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 
    NSLog(@"to url = %@",url); 
    [request appendPostData:[newJSON dataUsingEncoding:NSUTF8StringEncoding]]; 

    [request startSynchronous]; 
    NSString *responseString = [request responseString];  


    NSMutableDictionary* responseDict = [responseString JSONValue]; 
    NSLog(@"responseString = %@",responseString); 



    return responseDict; 
} 

方法は、私はそれを実行したとき、私はコンソール出力を取得するには、単に値を掲示し、戻り値を解析し、簡単です:

2012-05-02 12:06:29.414 Ushi.com[775:f803] what to send: {"phone":"123456","password":"123456","user_name":"tan"} 
2012-05-02 12:06:29.416 Ushi.com[775:f803] to url = http://api.uat.ushi.cn/user/getProfile?user_id=3 
2012-05-02 12:06:29.449 Ushi.com[775:f803] -JSONValue failed. Error is: Illegal start of token [<] 
2012-05-02 12:06:29.449 Ushi.com[775:f803] responseString = <html><head><title>Apache Tomcat/6.0.20 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 405 - Request method 'POST' not supported</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Request method 'POST' not supported</u></p><p><b>description</b> <u>The specified HTTP method is not allowed for the requested resource (Request method 'POST' not supported).</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.20</h3></body></html> 
(lldb) 

し、それをクラッシュ!しかし、もし私がライン[request appendPostData:[newJSON dataUsingEncoding:NSUTF8StringEncoding]];をコメントすると、私はデータを受信しますが、それはまたクラッシュします。 ありがとうございます...

答えて

1

これは、サーバーから取得したものが有効なJSONではなく、単純なhtmlであるためです。

問題は、サーバがPOSTをサポートしていないため、エラーページが返されることです。