bonjour,

J'ai crée une fonction me permettant d'envoyer des requêtes HTTP sur un serveur Apache.

Mais, je me suis rendu compte que les paramètres de ma requête n'étaient pas pris en compte par mon serveur.

J'ai l'impression que ma requête est interprétée comme étant une requête 'GET' et non une requete 'POST'.

Pouvez-vous m'aider s'il vous plait?

voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
private String sendPostHttpRequest( String url )
    {
        HttpConnection      hcon = null;
        DataInputStream     dis = null;
        DataOutputStream    dos = null;
        StringBuffer        responseMessage = new StringBuffer();
        // the request body
		String params = null;
 
        try {
            // an HttpConnection with both read and write access
            hcon = ( HttpConnection )Connector.open( url, Connector.READ_WRITE );
 
            // set the request method to POST
            hcon.setRequestMethod(HttpConnection.GET);
			hcon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			hcon.setRequestProperty("If-Modified-Since",  "29 Oct 1999 19:43:31 GMT" );	
			hcon.setRequestProperty("Content-Language", "en-US" );
            hcon.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
			hcon.setRequestProperty("Content-Type", "*/*");
 
            // obtain DataOutputStream for sending the request string
            dos = hcon.openDataOutputStream();
 
			//params = "auth=2&id=2";
			params = "";
 
			byte[] request_body = params.getBytes();
			for (int i = 0; i < request_body.length;/*&lt; params.length; */i++)
			{
				dos.writeByte(request_body[i]);
			}
 
			//dos.write(params.getBytes());
 
            // obtain DataInputStream for receiving server response
            dis = new DataInputStream( hcon.openInputStream() );
 
            // retrieve the response from server
			int ch;
			while ((ch = dis.read()) != -1)
			responseMessage.append((char)ch);
        }
        catch( Exception e )
        {
            e.printStackTrace();
            responseMessage.append( "ERROR" );
        } 
        finally 
		{
            // free up i/o streams and http connection
            try 
			{
                if( hcon != null ) hcon.close();
                if( dis != null ) dis.close();
                if( dos != null ) dos.close();
            } catch ( IOException ioe ) {
                ioe.printStackTrace();
            }//end try/catch 
        }//end try/catch/finally
        return (params + " " + responseMessage.toString());
    }//end sendHttpPost( String )