WebService Correios via post ASP
Boa tarde,
Vocês já tentaram consumir o Webservice dos correios via ASP Classico?
Estou com o seguinte problema (utilizo o componente MSXML2.XMLHTTP) se consumo via GET funciona, se consumo via POST não funciona, olhem o código (gostaria de consumir via POST):
Dim url : url = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx"
Dim method : method = "CalcPrecoPrazo"
Dim retorno : retorno = ""
Dim getXML
Set getXML = Server.CreateObject("MSXML2.XMLHTTP")
getXML.open "POST", url & "/" & method, false
getXML.setRequestHeader "Content-Type", "text/XML"
getXML.Send "nCdEmpresa=&sDsSenha=&nCdServico=40010&sCepOrigem=03113070&sCepDestino=03142001&nVlPeso=1&nCdFormato=1&nVlComprimento=30&nVlAltura=10&nVlLargura=20&nVlDiametro=0&sCdMaoPropria=N&nVlValorDeclarado=100&sCdAvisoRecebimento=S"
retorno = getXML.responseText
Set getXML = Nothing
Com o código acima obtenho o erro:
Server Error in '/calculador' Application.
Request format is unrecognized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Request format is unrecognized.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Request format is unrecognized.] System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +388 System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +94 System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, String path, String pathTranslated, Boolean useAppConfig) +698 System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +95 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +173
Version Information: Microsoft .NET Framework Version:1.1.4322.2502; ASP.NET Version:1.1.4322.2470
Se eu utilizar via GET, como abaixo, funciona:
Dim url : url = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo?nCdEmpresa=&sDsSenha=&nCdServico=40010&sCepOrigem=03113070&sCepDestino=03142001&nVlPeso=0.3&nCdFormato=1&nVlComprimento=30&nVlAltura=10&nVlLargura=20&nVlDiametro=0&sCdMaoPropria=N&nVlValorDeclarado=100,2&sCdAvisoRecebimento=S"
Dim getXML
Set getXML = Server.CreateObject("MSXML2.XMLHTTP")
getXML.open "GET", url, false
getXML.setRequestHeader "Content-Type", "text/XML"
getXML.Send
retorno = getXML.responseText
Set getXML = Nothing
Se alguém tiver uma sugestão.
Obrigado,
Michael C.
Discussão (5)
Carregando comentários...