【发布时间】:2014-05-23 08:27:08
【问题描述】:
我想在 android 中使用 webview 发布数据。试过下面的代码,
String postdata="username=abcd";
myWebView.postUrl(url, EncodingUtils.getBytes(postData, "BASE64"));
但没有得到想要的输出。如果有其他方法可以在 webview 中发布数据,请告诉我。
在 IOS 中也进行了同样的操作,并成功实施。下面是IOS中的代码:
NSString *loginUrl = @"https://www.abcdefgh.com/SellOnline/j_spring_check";
NSURL *url = [NSURL URLWithString:loginUrl];
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
// POST the username password
[requestObj setHTTPMethod:@"POST"];
NSString *postString = [NSString stringWithFormat:@"agent=%@", @"839878"];
NSData *data = [postString dataUsingEncoding: NSUTF8StringEncoding];
[requestObj setHTTPBody:data];
self.webview.delegate = self;
[self.webview loadRequest:requestObj];\
【问题讨论】:
-
你得到什么输出?因为这在我看来是正确的,所以也许您忘记了您的 postdata 中的某些内容?我需要更多信息。
-
我希望 web 视图中的页面通过登录会话打开,但现在它要求我提供登录凭据。
-
您的意思是您正在登录本机应用程序,例如使用 webservice(http 调用)以及您希望通过 webview 与 httpclient 的同一会话进行的一些进一步处理。简而言之,您正在尝试在 webview 和 Httpclient 之间同步 cookie 对吗?
-
@Biraj- 是的,你是对的。本地登录后,我试图在 webview 中发布 url
-
使用“UTF-8”更改 Base64 这可能会有所帮助
标签: android post webview http-post