検索

ホームページ  >  に質問  >  本文

ios - 我用AFN发送一个GET请求,返回来却报一个错

我的代码如下

+ (void) get:(NSString *)url parameters:(NSDictionary *)params success:(void (^)(id responseObj))success failure:(void (^)(NSError *error))failure;
{
    //获得请求管理者
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];//请求
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithArray:@[@"text/html",@"text/plain"]];

    [manager GET:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@", operation.request.URL);
        success(responseObject);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        NSLog(@"operation: %@" , operation.responseString );
        failure(error);
    }];
}

返回的错误信息是:
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7fcad2a51c30 {NSDebugDescription=Invalid value around character 0., NSUnderlyingError=0x7fcad2aadca0 "Request failed: internal server error (500)"}

我用operation.responseString打印的结果如下:

operation: <html><head><title>Apache Tomcat/6.0.37 - 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 500 - java.lang.NoSuchMethodException: com.kdtech.action.BusinessAction.myTask(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)</h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u>java.lang.NoSuchMethodException: com.kdtech.action.BusinessAction.myTask(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>javax.servlet.ServletException: java.lang.NoSuchMethodException: com.kdtech.action.BusinessAction.myTask(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
</pre></p><p><b>root cause</b> <pre>java.lang.NoSuchMethodException: com.kdtech.action.BusinessAction.myTask(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    java.lang.Class.getMethod(Class.java:1665)
    org.apache.struts.actions.DispatchAction.getMethod(DispatchAction.java:322)
    org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:262)
    org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/6.0.37 logs.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.37</h3></body></html>

实在是找不到原因了,求各位大大答疑解惑!!

PHP中文网PHP中文网2772日前615

全員に返信(1)返信します

  • PHP中文网

    PHP中文网2017-04-17 14:59:12

    カスタマイズされているため、リクエストヘッダー情報をすべて記述する必要があります。それ以外の場合は、カスタマイズせずにデフォルトのものを使用します。また、返されたデータを受け入れるにはデフォルトの形式を使用します。最終的にはブロックが空になる可能性があるので、条件判定を追加した方が良いでしょう。

    返事
    0
  • キャンセル返事