我正在尝试将ASIHTTPRequest包装器应用于非常基本的Objective C程序。我已经将必要的文件复制到我的程序中,并且在给自己极度头疼之后试图通过他们的网站弄清楚它是如何工作的,我想我会在这里发布一个问题。复制的文件是:
ASIHTTPRequestConfig.h
ASIHTTPRequestDelegate.h
ASIProgressDelegate.h
ASIInputStream.h
ASIInputStream.m
ASIHTTPRequest.h
ASIHTTPRequest.m
ASIFormDataRequest.h
ASIFormDataRequest.m
我的节目非常基础:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Defining the various variables.
char firstName[20];
char lastName[20];
char rank[5];
int leaveAccrued;
int leaveRequested;
// User Input.
NSLog (@"Please input First Name:");
scanf("%s", &firstName);
NSLog (@"Please input Last Name:");
scanf("%s", &lastName);
NSLog (@"Please input Rank:");
scanf("%s", &rank);
NSLog (@"Please input the number leave days you have accrued:");
scanf("%i", &leaveAccrued);
NSLog (@"Please input the number of leave days you are requesting:");
scanf("%i", &leaveRequested);
// Print results.
NSLog (@"Name: %s %s", firstName, lastName);
NSLog (@"Rank: %s", rank);
NSLog (@"Leave Accrued: %i", leaveAccrued);
NSLog (@"Leave Requested: %i", leaveRequested);
[pool drain];
return 0;
}
如何利用包装器通过http请求将这5个基本变量导出到Web服务器?
答案 0 :(得分:0)
从其他网站得到答案:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/post-data"]];
[request setPostValue:[NSString stringWithCString:firstName encoding:NSUTF8StringEncoding] forKey:@"firstName"];
[request setPostValue:[NSString stringWithFormat:@"%i",leaveAccrued] forKey:@"leaveAccrued"];
[request startSynchronous];
NSLog(@"%@",[request responseString]);