ASIFormDataRequest在模拟器上起作用,但在设备上不起作用? [英] ASIFormDataRequest works on simulator but not on device?

查看:67
本文介绍了ASIFormDataRequest在模拟器上起作用,但在设备上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASIFormDataRequest发布三个值,分别是url,标题和摘要.它们在模拟器上都可以正常工作,但在设备上不起作用.这是我正在使用的代码:

I am using ASIFormDataRequest to post three values which are a url, a title and a summary. All of them works fine on simulator but its not working on device. Here are the code that I'm using:

- (IBAction)addLinkPressed:(UIButton *)sender {

    ASIFormDataRequest *loginRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://MyWebsite.com/login.php"]];
    [loginRequest setRequestMethod:@"POST"];
    [loginRequest setPostValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"defaultUsername"] forKey:@"username"];
    [loginRequest setPostValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"defaultPassword"] forKey:@"password"];
    [loginRequest setUseKeychainPersistence:YES];
    [loginRequest setDelegate:self];

    [loginRequest setDidFinishSelector:@selector(requestLoginFinished:)];
    [loginRequest setDidFailSelector:@selector(requestLoginFailed:)];
    [loginRequest startSynchronous];



    NSString *strURL = @"http://MyWebsite.com/send_link.php";
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]];
    [request setDelegate:self];
    [request setPostValue:self.linkField.text forKey:@"url"];
    [request setPostValue:self.linkTitleField.text forKey:@"title"];
    [request setPostValue:self.linkSummaryField.text forKey:@"summary"];

    [request setDidFinishSelector:@selector(requestDone:)];
    [request setDidFailSelector:@selector(requestWentWrong:)];
    [request startAsynchronous];
}

任何人都可以帮助我!

推荐答案

首先:不再支持ASIRequest.已知在某些情况下有错误,并且错误不会得到修复.

First of all: ASIRequest is not anymore supported. It is known to be buggy in some cases and that bugs won't be fixed.

第二,关于您的问题,我看到可能会发生错误的两个地方(模拟器和设备之间的差异):

Second one, regarding your question, I see two places where error could occur (difference between simulator and device):

  1. 您确定设备上的 [[NSUserDefaults standardUserDefaults] objectForKey:@"defaultUsername"] [[NSUserDefaults standardUserDefaults] objectForKey:@"defaultPassword"] 设置正确吗?

在iOS模拟器上,您无权访问钥匙串,因此此设置( [loginRequest setUseKeychainPersistence:YES]; )也会在设备上引起问题.

On iOS simulator you have not got access to keychain so this setting ([loginRequest setUseKeychainPersistence:YES];) could cause problems on the device too.

我建议检查 NSUserDefaults ,最好使用另一个框架,即RestKit

I advice to check NSUserDefaults and better use another one framework, i.e. RestKit

已编辑

使用RestKit的示例:

Example of using RestKit:

[RKClient clientWithBaseURLString:@"http://example.com"];
RKClient *rkclient = [RKClient sharedClient];
RKParams *params = [RKParams paramsWithDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   username, @"username",
                                                   password, @"password", nil]];
[rkclient post:@"/profile" params:params delegate:self];

// implement needed delegate methods

这篇关于ASIFormDataRequest在模拟器上起作用,但在设备上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆