程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-同步post上傳參數的問題

ios-同步post上傳參數的問題

編輯:編程綜合問答
同步post上傳參數的問題

.h文件#import

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *username;

@property (weak, nonatomic) IBOutlet UITextField *pwd;

  • (IBAction)signin:(id)sender;

@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&parameter=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&parameter=pwd###%@#####userNo###%@& LoginID=&LoginIp=", username, psw];//設置參數

weixin_30260663
weixin_30260663
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved