How to Post arguments
How to Post arguments
- Subject: How to Post arguments
- From: "Manoj_Agrawal" <email@hidden>
- Date: Mon, 11 Sep 2006 10:50:18 +0530
- Importance: normal
- Priority: normal
- Thread-topic: How to Post arguments
Can you please help me out in passing morethan two arguments to the server (i.e backend)
The code that i am using is given below.
Can you suggest some modifications in it or some other code to achive the same.
- (IBAction)convert:(id)sender
{
int num1,num2;
num2 =[dollarField floatValue];
num1 = [rateField floatValue];
NSNumber *number1 = [NSNumber numberWithInt:num1];
NSNumber *number2 = [NSNumber numberWithInt:num2];
NSString* tempurlstring;
NSString* URLString;
NSString* resultString;
NSMutableData *receivedData=nil;
unsigned char *firstBuffer,*buffer;
NSURLConnection* theConnection;
int stringlen;
tempurlstring = [NSString stringWithCString:"http://145.36.149.31:8080/CBuild/servlet/HelloAddition"];//?input1=" encoding:NSASCIIStringEncoding];
//URLString = [tempurlstring stringByAppendingFormat:@"%@ &input2=%@", number1,number2];
//NSURL *URL = [NSURL URLWithString:tempurlstring];
NSString *inputs;
NSString *tempinputs;
tempinputs = [NSString stringWithCString:"input_1="];
inputs = [tempinputs stringByAppendingFormat:@"%@ &input_2=%@", number1,number2];
//NSURLRequest * postURLRequest = [NSURLRequest initWithURL:URL];
NSMutableURLRequest *postURLRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:tempurlstring]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
//NSMutableURLRequest* postURLRequest=[NSMutableURLRequest requestwithURL:URL];
[postURLRequest setHTTPMethod:@"POST"];
[postURLRequest setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
//NSURL *inputURL = [NSURL URLWithString:inputs];
//NSData *data = [NSData dataWithContentsOfURL:inputURL];
//if([inputs getCString:(char *)buffer maxLength:strlen encoding:NSASCIIStringEncoding] == YES)
/* NSString *input1,*temp1;
NSString *input2,*temp2;
temp1 = [NSString stringWithCString:"input_1="];
input1 = [temp1 stringByAppendingFormat:@"%@", number1];
temp2 = [NSString stringWithCString:"input_2="];
input2 = [temp2 stringByAppendingFormat:@"%@", number2];
NSData *data1 = [NSData dataWithBytes:input1 length:[input1 length]];
[postURLRequest setHTTPBody:data1];
NSData *data2 = [NSData dataWithBytes:input2 length:[input2 length]];
[postURLRequest setHTTPBody:data2];
*/
NSData *data = [NSData dataWithBytes:inputs length:[inputs length]];
[postURLRequest setHTTPBody:data];
/* [postURLRequest setHTTPBody:[@"input_1=4" dataUsingEncoding:NSISOLatin1StringEncoding]];
[postURLRequest setHTTPBody:[@"input_2=6" dataUsingEncoding:NSISOLatin1StringEncoding]];
*/
//[postURLRequest setHTTPMethod:[@"input1=%@number1" datausingencoding:NSISOLatin1StringEncoding]];
theConnection=[[NSURLConnection alloc] initWithRequest:postURLRequest delegate:self];
if (theConnection)
{
receivedData=[[NSMutableData data]retain];
}
//NSString* URLString1 = [NSString stringWithCString:"http://145.36.149.31:8080/CBuild/servlet/HelloAddition?input1=32&input2=12" encoding:NSASCIIStringEncoding];
//NSURL *myURL = [NSURL URLWithString:URLString];
//NSData *urlContents = [myURL resourceDataUsingCache:YES];
firstBuffer = [receivedData mutableBytes];
resultString = [NSString stringWithCString:firstBuffer];
[amountField setStringValue:resultString];
DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden