post http problem in cocoa
post http problem in cocoa
- Subject: post http problem in cocoa
- From: Athahar <email@hidden>
- Date: Sat, 2 Sep 2006 20:30:45 +0530
Hi i'm trying to build a simple addition tool, taking two numbers from the
user input in Cocoa, and processing in a server via HTTP post method.
in the server i've a java program to accept the variables from the cocoa
appln.
but my java program is not able to receive the variables.
what could be the problem with my code.
I've attached the code below.
#import "ConverterController.h"
@implementation ConverterController
- (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://<machine-name>:8080/CBuild/servlet/HelloAddition"];
NSString *inputs;
NSString *tempinputs;
tempinputs = [NSString stringWithCString:"input_1="];
inputs = [tempinputs stringByAppendingFormat:@"%@ &input_2=%@",
number1,number2];
NSMutableURLRequest *postURLRequest=[NSMutableURLRequest
requestWithURL:[NSURL URLWithString:tempurlstring]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[postURLRequest setHTTPMethod:@"POST"];
[postURLRequest setValue:@"text/xml"
forHTTPHeaderField:@"Content-type"];
NSData *data = [NSData dataWithBytes:inputs length:[inputs
length]];
[postURLRequest setHTTPBody:data];
theConnection=[[NSURLConnection alloc] initWithRequest:postURLRequest
delegate:self];
if (theConnection)
{
receivedData=[[NSMutableData data]retain];
}
firstBuffer = [receivedData mutableBytes];
resultString = [NSString stringWithCString:firstBuffer];
[amountField setStringValue:resultString];
}
@end
thanks
Aths
_______________________________________________
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