I'm using XhmHttp request object to send SOAP request to web services from classic asp page. The web service is returning xml string as result how can I read the xml string result from the SOAP response. Is there any property or method in the XmlHttp object supports that?
vb example:
Dim xmlhttp As New Msxml2.XMLHTTP30
xmlhttp.open "GET", "http://localhost/books.xml", False
xmlhttp.send
MsgBox xmlhttp.responseXML.xml
have a look at the description
responseXML Property
You should be able to use the regular XMLDOM object to do the whole thing. You just 'load' the document right from the URL of the web service you're talking to.
set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async=false
xmlDoc.load("http://server.domain.com/yourservice.asp?arg1=a")
Then you just continue parsing the document as if you had loaded it up from a local file.
Related
I am using B4A for calling ASMX service also used httputils2 library.
I use the following code for calling service:
Private httprequest As HttpJop
httprequest.Initialize("Job1", Me)
httprequest.PostString("http://192.168.1.104/service.asmx/query","mysql="&"insert into users (facebook_id) values ('ersdxc')")
When I run my application, I get this error:
java.lang.IllegalArgumentException: Request must not be null.
How can I fix it?
You will have to :
load in your browser the asmx file when it is compiled
click on the method
copy the post soap
copy the headers (content-type and SOAPaction)
generate in B4A a multiline string literal with the soap (f.e. stringliteral = $"..."$)
replace in this string literal the string query with the value "mysql=insert into users (facebook_id) values ('ersdxc')" which you will have to urlencode with stringutils and on the asmx side urldecode.
post the string literal with the headers f.e.
Private httprequest As HttpJop
httprequest.Initialize("Job1", Me)
httprequest.PostString("http://192.168.1.104/service.asmx/query", stringliteral)
httprequest.GetRequest.SetContentType("text/xml; charset=utf-8")
httprequest.GetRequest.SetHeader("SOAPAction", """REPLACE_WITH_YOUR_SOAP_ACTION_HERE""")
Please also note that the HttpUtils2 is deprecated and you will have to use the OkHttp and OkHttpUtils2 libraries. There is no difference in the code when using these two libraries.
I have to implement a Vertx POST request. Via Postman, the request is done as shown in the following picture:
The tricky part is that the server expects the key "upgrade_file" for the body. I could not find out how to do that with Vertx. This is what I have so far:
Buffer bodyBuffer = Buffer.buffer(body); // body is byte[]
HttpClientRequest request = ...
request.handler( response -> ...
request.end(bodyBuffer);
How can I set "upgrade_file" as the key for the body?
Use a WebClient instead of the HTTP client, it provides dedicated support for submitting forms.
WebClient client = WebClient.create(vertx);
or if you already have created an http client:
WebClient client = WebClient.wrap(httpClient);
Then create the form data as map and send the form using a the right content type
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.set("upgrade_file", "...");
// Submit the form as a multipart form body
client.post(8080, "yourhost", "/some_address")
.putHeader("content-type", "multipart/form-data")
.sendForm(form, ar -> {
//do something with the response
});
More example see https://vertx.io/docs/vertx-web-client/java/
If you want to send files, the simplest way is using the sendMultipartForm method of Vertx WebClient.
Create a Multipartform firstly.
MultipartForm form = MultipartForm.create()
.attribute("imageDescription", "a very nice image")
.binaryFileUpload(
"imageFile",
"image.jpg",
"/path/to/image",
"image/jpeg");
Then invoke WebClient.sendMultipartForm(form) to send the request.
The generic Vertx HttpClient is a low-level API, you should searialize the form data into a string or buffer, the format is similar to this example file in Vertx GraphQL testing codes. Then send the buffer to the server side.
Is there a way to get the parameters set in a post-delete-put REST request? in a proxy or programmatically developing a mediator (i mean in the MessageContext object passed to the mediate method)?
I know that parameters are appended to the url in a GET request e they appear by
getProperty("REST_URL_POSTFIX");
What about the other CRUD commands?
To get programatically, you can retrive those details from Axis2 messagecontext.
HttpServletRequest obj = (HttpServletRequest)
msgContext.getProperty("transport.http.servletRequest");
System.out.println("Method :" + obj.getMethod());
Here is a detail post
I have been trying to set up a sample AngularJS app with webMethods Integration Server on the backend. Using $resource, I can easily pull normal JSON files and manipulate the data within the file. However, the goal is that I want to create services in webMethods Designer and call them from AngularJS using $resource to display the data in my app. The problem is that from AngularJS I cannot extract the data I need from the service that I'm creating in Designer. In Designer I can use (in WMPublic) documentToJSONString, and output something like:
jsonString {"id":"1", "name":"Dan", "quantity":"3"}
But I cannot extract the data because this is not a pure JSON string. Does anyone know how to (1) extract the JSON string output data using AnularJS or (2) output a JSON document from Designer? I am calling a REST service; something to the effect of
http://localhost:2222/rest/Get/getOrderData
from my services.js file in AngularJS.
Here is my services.js file:
/* Services */
var orderServices = angular.module('orderServices', ['ngResource']);
orderServices.factory('Order', ['$resource',
function($resource){
return $resource('http://localhost:2222/rest/REST/getOrderData', {}, {
query: {method:'GET', isArray:true}
});
}]);
Then, in my app, I want to use an ng-repeat to call things like {{order.id}}, {{order.name}} etc. Is anyone good with webMethods and Angular or done this before?
To force the response that you want, I would have used the service
pub.flow:setResponse mapping the jsonString to it's string parameter and probably hardcoded (eww!) the contentType parameter to 'application/json'
You may also need to use the service pub.flow:setResponseCode to set the response code.
They would be the last services in getOrderData
I would have invoked it using the below (where namespace is the folder structure in designer)
http://localhost:2222/invoke/namespace:getOrderData
The above applies to Integration Server V8 and it looks like you're using V9 since some of the services that you mention didn't exist in V8. This would also apply to a normal flow service, not a specific REST one (assuming they exist in V9).
Recently I was using RestSharp to consume my Restful Resouce. and expected exchanging data with JSon between server and client. Below is my C# code.
var client = new RestSharp.RestClient();
var request = new RestRequest(sUrl,Method.POST);
request.RequestFormat = DataFormat.Json;
request.Timeout = TIME_OUT_MILLISECONTS ;
request.AddHeader("Content-Type", "application/json");
request.AddBody(new { appID = sAppId, loginName = sUserName, password=sPassword });
var response = client.Execute(request);
string s=response.Content;//It is always XML format.
The result is not what I expected for(Json data format), although I had set the RequestFormat Json and add Http header Content-Type. So I decided to use the .Net Reflector to found out What happened in the RestClient.Execute method. Here is the code of the method.
public RestClient()
{
...
this.AddHandler("application/json", new JsonDeserializer());
this.AddHandler("application/xml", new XmlDeserializer());
this.AddHandler("text/json", new JsonDeserializer());
this.AddHandler("text/x-json", new JsonDeserializer());
this.AddHandler("text/javascript", new JsonDeserializer());
this.AddHandler("text/xml", new XmlDeserializer());
this.AddHandler("*", new XmlDeserializer());
...
}
I have some questions about it:
As the RestClient adds many kinds of Content-Type into the HttpWebRequest. Is it right way to build a Request? And I think Maybe that is the reason why Response.Content always XML.
I don't know why the RestClient needs to build a HttpWebRequest like that. Any meaning to do that?
If we specified both JSon and XMl message format in a Http Request, which one works finally? Is it allowed?
Thanks. Have a good day.
RestSharp will use the correct handler based on the content type of the response. That's what those AddHandlers are doing; its configuring the RestClient to accept certain content types in the response and mapping those types to deserializers. Normally you would want to set an accept header for the json content type which notifies the server to send json in the response.
request.AddHeader("Accept", "application/json")
Of course, this assumes that the server you are hitting is configured to respond with json.