0

我的问题是我无法将短信发送到服务器。我正在使用 asihttprequest。我自己定义了 USERNAME、UUID、PASSWORD、API_PASSWORD 和 NUMBER。我想要做的只是将数据发送到给定的服务器 url。这是我的代码:

    - (IBAction)sendClicked:(id)sender {

    [sendButton resignFirstResponder];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL   URLWithString:@"https://cc.frifon.net_dosmssend/"]];
    [request setDelegate:self];
     [request setNumberOfTimesToRetryOnTimeout:3];
    [request setRequestMethod:@"POST"];
    [request setPostValue:USERNAME forKey:@"sip"];
    [request setPostValue:PASSWORD forKey:@"pwd"];
    [request setPostValue:UUID forKey:@"uuid"];
    [request setPostValue:API_PASSWORD forKey:@"key"];
    [request setPostValue:messageText forKey:@"message"];
    [request setPostValue:NUMBER forKey:@"to"];
    [request setPostValue:@"Submit" forKey:@"submit"];
       [request start];
    nil;

    [request startAsynchronous];
     }

- (void)requestFinished:(ASIHTTPRequest *)request {
NSError *error = [request error];
if (!error) {
    NSString *response = [request responseString];
    messageText.text = response;
}

}
4

2 回答 2

0

尝试这个,

- (IBAction)sendClicked:(id)sender {

    [sendButton resignFirstResponder];
    NSString *serviceString = https://cc.frifon.net_dosmssend/;
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[serviceString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
    [request setDelegate:self];
     request.requestMethod = @"POST";
    request.timeOutSeconds = 30.0;
    [request addPostValue:USERNAME forKey:@"sip"];
    [request addPostValue:PASSWORD forKey:@"pwd"];
    [request addPostValue:UUID forKey:@"uuid"];
    [request addPostValue:API_PASSWORD forKey:@"key"];
    [request addPostValue:messageText forKey:@"message"];
    [request addPostValue:NUMBER forKey:@"to"];
    [request addPostValue:@"Submit" forKey:@"submit"];

    [request startAsynchronous];
  }
于 2013-10-25T08:59:07.073 回答
0
- (IBAction)sendClicked:(id)sender {
 // Add you all data in below dictionary 
 NSDictionary *dictionary = @{@"action":@"login",@"nick_name":nikname,@"password":pass};
 NSError *error;
 NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];

 NSString *jason =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

 NSLog(@"JSON summary: %@", jason);

 NSString *address = [NSString stringWithFormat:@"%@",@"www.demo.com"];

 address=  [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

 NSURL *URL = [NSURL URLWithString:address];

 NSLog(@"%@",address);

 // request creation
 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL cachePolicy:NSURLCacheStorageAllowedInMemoryOnly
                                                   timeoutInterval:60.0];

[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPBody:data];

 responseData = [[NSMutableData alloc] init];       

NSURLConnection *Conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[Conn start];
}
于 2013-10-25T09:17:44.963 回答