Transfert de fichier socket sans passer au socketServeur

bodo2011 Messages postés 9 Date d'inscription mardi 25 janvier 2011 Statut Membre Dernière intervention 11 juin 2012 - 1 juin 2012 à 16:43
 Utilisateur anonyme - 2 juin 2012 à 13:27
bjr a tous!
Je fait un tranfert de fichier socket(client /serveur) ss passer au socketServeur
Voici mon code:

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.*;
import java.net.*;

public class FileUploadDemo1 {
public static void main(String[] args) {
httpClient client = new httpClient();
URL url = new URL("http://localhost/lbmis-dev/server-scripts/grievance/upl.php");
PostMethod mPost = new PostMethod(url);
MultipartPostMethod mPost = new MultipartPostMethod(url);


// Send any XML file as the body of the POST request
File f1 = new File("C:/aa.jpg");

try {
mPost.addParameter("monFichier", f1);

} catch (FileNotFoundException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
}

try {
int statusCode1 = client.executeMethod(mPost);

if (statusCode1 == HttpStatus.SC_OK) {
appendMessage(
"Upload complete, response=" + mPost.getResponseBodyAsString()
);
} else {
appendMessage("Upload failed, response=" + HttpStatus.getStatusText(statusCode1) + " "+mPost.getResponseBodyAsString()
);
}

} catch (HttpException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
} catch (IOException e) {
// TODO Bloc catch auto-généré
e.printStackTrace();
}


System.out.println("statusLine>>>" + mPost.getStatusLine());
mPost.releaseConnection();
System.out.println("OK");

}
}
Je suis coince sur des beugs.Est ce quelqu'un peut m'aide SLVP?
Voici les beugs:
-error:no suitable constructor found for PostMethod(URL)
-error:cannot find symbol : class MultipartPostMethod
-error:cannot find symbol : class httpClient
-error: mPost is already defined in main(String[])

1 réponse

Utilisateur anonyme
2 juin 2012 à 13:27
error: mPost is already defined in main(String[])

Tu as deux variables qui portent le même nom à savoir mPost. Tu devrais en renommer une des deux.


Pour info,
import org.apache.commons.httpclient.methods.PostMethod;

ne sert à rien car tu l'as déjà importé avec
import org.apache.commons.httpclient.*; 


-error:cannot find symbol : class MultipartPostMethod
-error:cannot find symbol : class httpClient


Vérifie si tu as bien importé les classes httpClient et MultipartPostMethod. Honnêtement, j'ai des doutes que ta classe httpClient existe, ou alors tu l'as mal écrite.

-error:no suitable constructor found for PostMethod(URL)

Tu n'utilises pas le bon constructeur, visiblement il n'y en a pas qui prennent une URL pour PostMethod.

Bref, vérifie si tu as fait de bonnes importations.

--
Pylouq
(Lire le Réglement n'a jamais tué personne, au pire ça a instruit des gens.)
0
Rejoignez-nous