0

Once again I need your help with an issue:

I'm currently implementing an app, which communicates with a network electrical-socket. Therefore I'm sending a "selfmade" http-request. This works fine as long as I'm using WiFi or having o2 as provider (I'm living in Germany). But as soon as I use mobile internet with Vodafone, I get bullshit as response.

Here is, what I do:

checkDosenTimer: function(){
        var header =
            "GET /dd.htm?DD" + dosenId + " HTTP/1.1\r\n"
            +"Host: " + ip + "\r\n"
            +"Connection: keep-alive\r\n"
            +"Authorization: Basic " + Base64.encode(userName+":"+password) + "\r\n"
            +"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
            +"User-Agent: Mozilla/5.0 (Linux; Android 4.1.1; HTC One S Build/JRO03C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.90 Mobile Safari/537.36\r\n"
            +"Referer: http://" + ip + "mobile.htm\r\n"
            +"Accept-Encoding: gzip,deflate,sdch\r\n"
            +"Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4\r\n"
            +"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3;\r\n\r\n";
        var that = this;    
        cordova.exec(
            function(succ){
                that.processTimerResult(succ);
            },
            function(err){
                console.log("Error bei HTTPController sendMessage: "+err);
            },
            "HttpController",
            "sendMessage",
            [header,'',ip,httpPort]
        );
    }

So what I do is, I set up my header in JavaScript and passing it to the Java method sendMessage within the HttpController, which has the following form:

private void sendMessage(JSONArray args, 
                    CallbackContext callbackContext) 
    throws JSONException {
        String header = args.getString(0); 
        String body = args.getString(1);
        String routerIp = args.getString(2);
        int routerPort = args.getInt(3);

        Tcp tcp = new Tcp();
        String result = tcp.sendMessage(header,body,routerIp,routerPort);
        callbackContext.success(result);
    }

Finally, we arrive in the method sendMessage in Tcp:

public String sendMessage(String header,String body, String routerIp, int routerPort) {
        String respond = "";
        Socket socket = null ;
        try {
           //Create socket
           socket = new Socket(routerIp, routerPort);
           socket.setSoTimeout(10000);
           //Send header
           BufferedWriter  wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"UTF-8"));
           // You can use "UTF8" for compatibility with the Microsoft virtual machine.

            wr.write(header);
            wr.flush();
            //Send data
            wr.write(body);
            wr.flush();

            // Response
            BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line;

            while((line = rd.readLine()) != null)
                respond += line;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Error e){
        e.printStackTrace();

    }finally{
        final Pattern p = Pattern.compile("errorCode");
        final Matcher m = p.matcher(respond);
        if(!(m.find())){
            return respond;
        }else{
            return "no Respond from " + routerIp + " on Port:" + routerPort;
        }
    }       
}

First of all: thank you for reading so far :-)

I made shure, that the header-string in the Tcp class keeps the same. But the response which arrives at the Tcp class differs depending on the provider. With Vodafone, the Response looks like:

Bullshit response

The expected result ist something like:

Expected result

I guess that my provider (=vodafone) manipulates my GET-request for some reasons. Is this assumption possible? Is there a way how to get arround that?


As requested by Koterpillar:

Request:

Header:

GET /dd.htm?DD1 HTTP/1.1
Host: 134.3.157.233
Connection: keep-alive
Authorization: Basic ************
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Linux; Android 4.1.1; HTC One S Build/JRO03C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.90 Mobile Safari/537.36
Referer: http://134.3.157.223/mobile.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3;

Body: (empty)

Correct Response

HTTP/1.1 200 OKAccess-Control-Allow-Origin: *Connection: closeContent-Type: text/htmlCache-Control: no-cache<html><head><title>ANEL-Elektronik NET-PwrCtrl</title><link href="np.css" rel="stylesheet" type="text/css"><script language='JavaScript' src='valid.js'></script><form method=post action=dd.htm name=fr><table width=570><tr><td class=tb_hd1>Einstellung Steckdose Nr. 1</table><table width=570 class=f><tr><td width=104>Name:<td><input maxlength=16 size=16 name="TN" value="Beamer"><td>Max. 16 Zeichen</table><table width=570 height=186 class=f><tr bgcolor=#EEEEEE height=22><td width=104>Timer<td width=25><td width=115>Wochentag<td width=58>von<td width=57>bis<td><tr><td bgcolor=#EEEEEE>Timer 1<td bgcolor="#b0e0e0"><input type=checkbox name="T00" ><td><input size=6 name="T10" value=""> 1=So.<td><input size=3 onblur="return VT(this.value, this.name);" name="T20" value="00:00"><td><input size=3 onblur="return VT(this.value, this.name);" name="T30" value="00:00"><td style="font-size:8pt;">bei 99:99 - Schaltzeit aus.<tr><td bgcolor=#EEEEEE>Timer 2<td bgcolor="#b0e0e0"><input type=checkbox name="T01"  checked><td><input size=6 name="T11" value="12345"> 2=Mo.<td><input size=3 onblur="return VT(this.value, this.name);" name="T21" value="00:00"><td><input size=3 onblur="return VT(this.value, this.name);" name="T31" value="06:00"><td><tr><td bgcolor=#EEEEEE>Timer 3<td bgcolor="#b0e0e0"><input type=checkbox name="T02" ><td><input size=6 name="T12" value="346"> 3=Di.<td><input size=3 onblur="return VT(this.value, this.name);" name="T22" value="00:13"><td><input size=3 onblur="return VT(this.value, this.name);" name="T32" value="00:00"><td><tr><td bgcolor=#EEEEEE>Timer 4<td bgcolor="#b0e0e0"><input type=checkbox name="T03"  checked><td><input size=6 name="T13" value=""> 4=Mi.<td><input size=3 onblur="return VT(this.value, this.name);" name="T23" value="28:49"><td><input size=3 onblur="return VT(this.value, this.name);" name="T33" value="03:00"><td><tr><td bgcolor=#EEEEEE>Zufallstimer<td bgcolor="#b0e0e0"><input type=checkbox name="T04" ><td><input size=6 name="T14" value=""> 5=Do.<td><input size=3 onblur="return VT(this.value, this.name);" name="T24" value="00:00"><td><input size=3 onblur="return VT(this.value, this.name);" name="T34" value="00:00"><td>Intervall <input size=3 onblur="return VT(this.value, this.name);" name="T4" value="00:00"><font color=#CCCCCC> um 00:00</font><tr><td bgcolor=#EEEEEE colspan=6></table><table width=570 class=f><tr><td bgcolor="#F0F0F0" colspan="2">Nach dem Neustart (Stromausfall) Steckdose:<tr><td bgcolor="#FAFAFA" colspan="2"><input type=radio name="TF" value="e" >einschalten <input type=radio name="TF" value="w"  checked>Zustand wiederherstellen <input type=radio name="TF" value="a" >ausschalten<tr><td bgcolor="#E0E0E0" colspan="2"><tr><td bgcolor="#FAFAFA"><input type=checkbox name="TH" > Steuerung der Steckdose sperren.<td align=right bgcolor=#FAFAFA><input type=submit value=Speichern name="TS"></table></form><form method=post action=dd.htm id=a><div class="result ok" style="display:none">Ping - Test erfolgreich</div><div class="result fail" style="display:none">Ping - Test nicht erfolgreich</div><table style="font-size:7pt;" width=570><tr><td colspan=8 class=tb_hd>Keepalive Timer<tr bgcolor=#EEEEEE align=center><td colspan=2>Sende an die IP<td>ein Ping<td>alle (m)<td>und abschalten<td>wenn kein<br>Echo mal:<td>Reset<br>f�r (s)<td>nach (m)<br>fortsetzen<input type="hidden" name="KS"><tr align="center"><td bgcolor="#b0e0e0"><input type=checkbox name="K0" ><td><input size=15 name="K1" value="0.0.0.0"><td><input id=p type="submit" name="KA" value="Test"><td><input size=1 maxlength=3 style="text-align:center;" name="K2" value="1"><td><input type="submit" name="KB" value="Reset"><td><input size=1 maxlength=3 style="text-align:center;" name="K3" value="3"> x<td><input size=1 maxlength=3 style="text-align:center;" name="K4" value="60"><td><input size=1 maxlength=3 style="text-align:center;" name="K5" value="3"><tr bgcolor=#EEEEEE align=center><td colspan=2><td>

False Response (Yes, these symbols are actually what I get)

HTTP/1.1 200 OKContent-Length: 1464     Content-Encoding: gzipAccess-Control-Allow-Origin: *Content-Type: text/htmlCache-Control: no-cacheConnection: keep-alive���������������]o�0��'�?�l�H�E4�T��LMmRo&'1��q���~NX �*��$������cG�Y匦$2�F�g���`+��W0�,����g�Dt�K��+�[b$7N�5�F�&lt;�s��a�5�Uy�.҉��ʬ�ý/����h���&lt;u~���w�ռe�ְf&/R�)��^H������^�*��X0�����ҵkR�I!Tkl�y�   ��0!J��ܰd���L9��V/H�X�%w�����!q�)��V0�U���U��$Z��5��sv=G��ҭ6��$g�,7�^��TY�,)D��٤��D��t��L��A;�ȏ�r`hv�]![��$��]����ߕ�Bg���Hu{�j�*.��E@Z$kx{v�������&lt;;�BƢ�3���}���\;��OPW��P#��]w��/��-Uo��T��"-i��x�1W�Č�h4���$��<2n���k��8{G9{{㖲��Q�ڔ]Qn��W{38�������[�ox7��'�t���bO���m�Z��A;���q8�Z�^�-�Tm�S��£���aX���i�Rg�7�F�7���������W�o�0�WN�4QM���b�UT�Ъj�Ӿ|��ĉ���������pF�@   �c?�|��^Z��*GM�����e>n�LJ"�xr�O�����@MG��`F|��%j A�!XoAbXdy�s�-�d�$�̓�ƌ�;!g|�!]��@�I�w�~���0�B�#9S\P�C_���x���?J�[��:7>��\5eWP�_���|w"�,P�ţe;6/KQkT|T��泚j�J�L���bS1�Q-S�ӈ��l�J�0�t|�e�4�n2|)iD\ϊ(�d'*� �,��?c�(�cH���     �&amp;��5/drI�P� ����S��i ��X�ٱ8&��W���p�Ĕ���T�n�js�FV�֕�D%2D�d� "���ttz����`U�[^Q)�Q��J���6!{��3̹u��(cqs�s��p.�m(%�Jx˒�e���F ��~��}�a�Ա9����e�SZ�ϒ�^߬���s�y]�R����&�����E��X�����f�ϟ�)����pM�uԹSц��Nf9��)�_����{�ᐹ9��B����Y��v��uՙ�^��G��ү�����&lt;:H��u��AO�~yM#9�o�=d]*R�)�ТR7#*R��Т��Ou���t+���������C�ӱ�lX>Se�L�B��]f�FJ~ri.0n��SK\sRAL�J��L%MH������B����B`Ir]�mIQi�uyf^J~�0�@�g~i��\w����J:��ֵ@W�Nl���`��
4

1 回答 1

4

AFAICT,您声称接受 gzip 编码的内容,但实际上并不想/支持它。删除Accept-Encoding标题,或将其更正为您支持的任何内容

于 2013-06-09T12:53:44.613 回答