安卓:显示从服务器验证码验证码、服务器

2023-09-04 05:16:57 作者:骨子里都是戏

有关我的应用程序需要使用验证码进行验证。我使用这个链接吧: http://vocublablair.nl/webservices/send.php

它返回一个字符串是这样的:/webservices/simple-php-captcha.php?_CAPTCHA&t=0.59145200+1338304461

然后该链接应该叫做,存在:http://vocublablair.nl/webservices/simple-php-captcha.php?_CAPTCHA&t=0.59145200+1338304461

当我把这种具有相同的HttpClient(所以用正确的会话cookie),它提供了以下错误:

  java.lang.IllegalArgumentException:如果在索引94非法字符查询:http://vocublablair.nl/webservices/simple-php-captcha.php?_CAPTCHA&t=0.59145200+ 1338304461
 
返回验证码的服务器,看我是如何利用验证码把服务器弄崩溃

解决方案

我解决了这个问题做如下:

所有我得到的链接

先回必须是HTML EN codeD使用:

  Html.fromHtml(字符串)
 

调用正确的网址:

 内容= sb.toString(); //取出的链接
字符串的myCookie =;
//从其他的呼叫会话cookie。

名单<饼干> 。饼干=((DefaultHttpClient)的HttpClient).getCookieStore()的getCookies();
对于(曲奇C:饼干){
如果(c.getName()。等于(PHPSESSID)){
    的myCookie = c.getName()+=+ c.getValue();
    打破;
   }
   }

网址URL =新的URL(Html.fromHtml(http://vocublablair.nl+内容)的ToString());
URLConnection的连接= url.openConnection();
connection.setDoInput(真正的);
connection.setRequestProperty(曲奇,myCookie时);
connection.connect();
位图位= BitmapFactory.de codeStream(新FlushedInputStream((的InputStream)connection.getContent()));
 

我使用的是FlushedInputStream。在这里阅读有关:的http://twigstechtips.blogspot.com/2011/10/android-loading-jpgpng-images-from-url.html

For my application I need to use a captcha for verification. I am using this link for it: http://vocublablair.nl/webservices/send.php

It returns a string something like this: /webservices/simple-php-captcha.php?_CAPTCHA&t=0.59145200+1338304461

Then that link should be called, being: http://vocublablair.nl/webservices/simple-php-captcha.php?_CAPTCHA&t=0.59145200+1338304461

When I call this with the same HttpClient (so with the right session cookie) it gives the following error:

java.lang.IllegalArgumentException: Illegal character in query at index 94: http://vocublablair.nl/webservices/simple-php-captcha.php?_CAPTCHA&t=0.59145200+1338304461

解决方案

I solved the problem doing the following:

First of all the link I got back had to be HTML encoded using:

Html.fromHtml(String)

Calling the correct URL:

content = sb.toString(); //the fetched link
String myCookie = "";
//get session cookie from other call.

List<Cookie> cookies = ((DefaultHttpClient)httpClient).getCookieStore().getCookies();
for(Cookie c : cookies){
if(c.getName().equals("PHPSESSID")){
    myCookie = c.getName() + "=" + c.getValue();
    break;
   }
   }

URL url = new URL(Html.fromHtml("http://vocublablair.nl" + content).toString());
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setRequestProperty("Cookie", myCookie);
connection.connect();
Bitmap bit = BitmapFactory.decodeStream(new FlushedInputStream((InputStream) connection.getContent()));

I am using a FlushedInputStream. Read about it here: http://twigstechtips.blogspot.com/2011/10/android-loading-jpgpng-images-from-url.html