.h文件#import
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *pwd;
@end
.m文件中的按鈕方法- (IBAction)signin:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://14.17.84.128:8088/wcf/ActionService.svc/action/web/get/do?jsoncallback=?"];
//創建請求
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[request setHTTPMethod:@"POST"];
NSString *str = @"ActionCode =0x2001¶meter=pwd###123#####userNo###aaa& LoginID=&LoginIp=";//設置參數
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
//連接服務器
NSData *received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *str1 = [[NSString alloc]initWithData:received encoding:NSUTF8StringEncoding];
NSLog(@"%@",str1);
}
在上傳參數的時候,我應該怎樣子才能讓上傳參數中的123和aaa兩個參數變成我在textfield中輸入的參數呢?就是用文本框中輸入的參數寫入到post的參數中。請大神解答呀。
NSString * username = self.username.text;
NSString * psw = self.pwd.text;
NSString *str = [NSString stringWithFormat:@"ActionCode =0x2001¶meter=pwd###%@#####userNo###%@& LoginID=&LoginIp=", username, psw];//設置參數