2010-04-25 68 views
0

我想將ASIHTTPRequest包裝應用到一個非常基本的Objective C程序。我已經將必要的文件複製到我的程序中,並且在給我自己一個極端的頭痛之後試圖弄清楚它是如何通過他們的網站工作的,我想我會在這裏發佈一個問題。複製的文件是:Mac的ASIHTTPRequest包裝使用

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

得到了另一個站點的回答:

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]);