0

我正在尝试发出类似于此的发布请求

    $.ajax({
             url: "ValidationHandler.ashx",
             type: "POST",
             //data: "connectionid=" + connID +"&vp=" + vp,
             data: "connectionid=" +  connID + "&vp=" + vp,
             dataType: "json",
             async: false,
             error: function (XMLHttpRequest, textStatus, errorThrown) {
                 value = '00000'
             },
             success: function (response) {
                 try {
                     if ((response) || (response != 'object')) {  //if repsonse is NOT an object - make it an object!!!!
                         value = response.auth
                     }
                     else {
                         value = response.auth;
                     }
                 } catch (ex) {
                     value = response.auth;
                 }
             }
         });
         return value;

我目前在我的objective-c中有这个

NSString *url = @"http://ec2-176-34-72-223.eu-west-1.compute.amazonaws.com/Ext/RemoteLogin";
l
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setValue:@"email@biztweet.com" forHTTPHeaderField:@"email"];
[request setValue:@"password123" forHTTPHeaderField:@"password"];

NSLog(@"%@", request);
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
if(connection)
{
    myData = [NSMutableData data];
}

}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
 {
NSString *str = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];
NSLog(@"3: %@", str);
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"1: %@", error.description);
 }

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[myData setLength:0];
NSLog(@"2: %@", response.description);
}

 -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[myData appendData:data];
}

现在,当我使用它时,我将 html 代码作为响应返回,但我想获得由 c# 代码编写的响应。

context.Response.Write(GenerateConnectionAuthorisationString(connectionid));

我想得到一个字符串作为我的响应。javascript能够获得字符串响应。那我哪里错了??

4

0 回答 0