Envoyé par : wario
Date : 22/03/2005 12:18
Bonjour à tous,
J'essaye de créer un composant XpCom pour Thunderbird (en C++), utilisant le composant XMLHttpRequest. Voici le source du composant :
#include <nsCOMPtr.h> #include <nsString.h> #include <nsIURI.h> #include <nsIChannel.h> #include <nsIXMLHttpRequest.h> #include <nsNetUtil.h> #include "nsIDocument.h" #include "nsIServiceManager.h" #include "nsContentCID.h" #include "nsReadableUtils.h" #include <nspr.h> #include "nsIVariant.h"
/* void test (); */
NS_IMETHODIMP nsTest::Test()
{
nsresult rv;
PR_fprintf(PR_STDOUT, "CREATION DE L'INSTANCE\n");
nsCOMPtr<nsIXMLHttpRequest> pXMLHttpRequest = do_CreateInstance( NS_XMLHTTPREQUEST_CONTRACTID, &rv );
const char* url = "http://www.monsite.com/test.cgi";
const char* data = "val1=a&val2=b";
if (NS_FAILED( rv )) {
return rv;
}
const nsAString& emptyStr = EmptyString();
PR_fprintf(PR_STDOUT, "OUVERTURE DE LA REQUETE\n");
rv = pXMLHttpRequest->OpenRequest( NS_LITERAL_CSTRING("POST"),
nsDependentCString(url),
PR_FALSE, emptyStr, emptyStr );
if (NS_FAILED( rv )) {
return rv;
}
rv = pXMLHttpRequest->SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"),
NS_LITERAL_CSTRING("application/x-www-form-urlencoded"));
if (NS_FAILED( rv )) {
return rv;
}
nsCOMPtr < nsIWritableVariant > variant = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
rv = variant->SetAsACString(nsDependentCString(data)); if (NS_FAILED(rv)) return rv; PR_fprintf(PR_STDOUT, "ENVOI DE LA REQUETE\n"); rv = pXMLHttpRequest->Send( variant );
if (NS_FAILED( rv )) {
PR_fprintf(PR_STDOUT, "Probleme send %x\n", rv);
return rv;
}
return NS_OK;
}
Le fichier compile correctement, mais quand je teste le composant en utilisant xpcsell, j'ai l'erreur suivante au niveau du send() : error "0x80004005 (NS_ERROR_FAILURE)"
Est ce que quelqu'un peut m'aider ?
Merci d'avance
Envoyé par : wario
Date : 12/04/2005 09:33
Salut,
j'ai réussi à résoudre ce problème. En fait, j'utilisais un proxy pour me connecter sur le net, il fallait donc que je le configure dans mon code.
nsCOMPtr<nsIPrefBranchInternal> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if(prefBranch){
// preferences for the proxy
prefBranch->SetCharPref("network.proxy.http", "monproxy.server.fr");
prefBranch->SetIntPref("network.proxy.http_port", 3128);
prefBranch->SetIntPref("network.proxy.type", 1);
}
a+
Il n'est plus possible de poster des messages dans ce forum.
Copyright © 2003-2013 association xulfr, 2013-2016 Laurent Jouanneau - Informations légales.
Mozilla® est une marque déposée de la fondation Mozilla.
Mozilla.org™, Firefox™, Thunderbird™, Mozilla Suite™ et XUL™
sont des marques de la fondation Mozilla.