代码=-1016 "Request failed: unacceptable content-type: text/plain" 用户信息=0x7a2da380


AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    NSLog(@"%@",[urlOfVm class]);
    NSMutableString *url = [NSMutableString stringWithString:urlOfVm];
    [url appendString:in];
    NSLog(@"%@",url);
    NSURLRequest* request = [[AFJSONRequestSerializer serializer]requestWithMethod:@"POST" URLString:url parameters:diccp ];
    AFHTTPRequestOperation* operation = [manager HTTPRequestOperationWithRequest:request
                                                                         success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                                                             if (responseObject != nil) {
                                                                                 NSLog(@"----------------------response:%@",[operation responseString]);
                                                                                 NSLog(@"responseObject:%@",responseObject);
                                                                                 [self create:(NSDictionary *)responseObject];
                                                                             }
                                                                             else{
                                                                                 NSLog(@"return null");
                                                                             }

                                                                         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                                                             NSLog(@"response:%@",[error description]);
                                                                         }];
    [operation setResponseSerializer:[AFJSONResponseSerializer serializer] ];
    [[NSOperationQueue mainQueue] addOperations:@[operation] waitUntilFinished:NO];

下面是java interFace:

/**
     * user register 
     * if the method return 0 ,it means the user exists; return 1:it means register success, return 2 means the internet has some problem
     * 
     * @param parameter
     * @return
     */
    @RequestMapping(value = "/register")
    @ResponseBody
    public String registerAccount(@RequestBody Account account) {
        System.out.println(account.getUserName());
        Account account1 = accountManager.isExistAccountByUserName(account
                .getUserName());
        if (null != account1) {
            return "0";
        } else {
            try {
                account.setGenerateTime(DateUtils.formatTime(new Date()));
                String id = new SimpleDateFormat("SSSssmmHHddMMyy").format(new Date());
                account.setId(id);
                account.setIdType("1");
                account.setPhoneNumber(account.getUserName());
                accountManager.insertAccount(account);
                return "3";
            } catch (Exception e) {
                return "2";
            }
        }
    }

由于错误引用,您正在发送具有错误内容类型 ( text/plain 的请求。我想,您需要将内容类型更改为 JSON。为此,请添加 JSON 请求序列化程序:

[operation setRequestSerializer:[AFJSONRequestSerializer serializer]];

相关内容

  • 没有找到相关文章

最新更新