i am using ksoap/ksoap2 api for calling a php webservice from j2me.
For ksoap:
SoapObject client = new SoapObject(NAMESPACE, "ns2221:save_record");
client.addProperty("cc", "1234560789");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XmlWriter xw = new XmlWriter(new OutputStreamWriter(bos));
SoapEnvelope envelope = new SoapEnvelope(new ClassMap(Soap.VER11));
envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
envelope.setBody(client);
envelope.write(xw);
xw.flush();
bos.write('\r');
bos.write('\n');
byte[] requestData = bos.toByteArray();
String requestSOAPmesg = new String(requestData);
System.out.println("request Soap Message: " + requestSOAPmesg);
HttpTransport ht = new HttpTransport();
ht.setUrl(url);
ht.setSoapAction(NAMESPACE);
SoapObject o = (SoapObject) ht.call(client);
have used..
and in ksoap2
SoapObject client = new SoapObject("http://192.168.0.205:82/imageuploader/save_record.php#save_record", "ns8862:save_record");
client.addProperty("cc", "1234560789");
//Create Envelope for
Object so=soapMsg;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=false;
envelope.bodyOut=client;
System.out.println("Before Envelope");
HttpTransport ht = new HttpTransport(url);
ht.call("http://192.168.0.205:82/imageuploader/save_record.php#save_record", envelope);
SoapObject o=(SoapObject) envelope.getResponse();
have used..
it returns me
fault String:
faultstring: 'Operation 'ns8862:save_record' is not defined in the WSDL for this service' faultactor: '' detail: org.kxml2.kdom.Node#ea0ef881
in the web service the first tag ns8862:save_record changes every time a request is passed for the 4 numbers.
Any Solution?
Check the web service for capital letters. The error states that "save_record" is undefined. Maybe it's "Save_Record", or "saveRecord". Make sure you are adhering to the template.
Related
I am creating one webjob which needs to send mail of status of webjobs. I am using webjob API aka "https://xyz.scm.ase-03.com/api/triggeredwebjobs" to get the webjobs details. I am getting the response from my local httpclient call but while deploying it as a webjob on azure then I am getting null response. Here is my code:
var result = string.Empty;
var url = "https://domain.dev.xyz.com/api/";
var baseURL = "triggeredwebjobs";
string userPswd = "username " + ":" + "password"; // getting username and password from publish profile.
userPswd = Convert.ToBase64String(Encoding.Default.GetBytes(userPswd));
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(url);
client.Timeout = TimeSpan.FromMinutes(30);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",userPswd );
var response = new HttpResponseMessage();
response = client.GetAsync(baseURL).Result; // Here I am getting null value.
result = response.IsSuccessStatusCode ? (response.Content.ReadAsStringAsync().Result) : response.IsSuccessStatusCode.ToString();
}
I am in doubt that calling self webjobs api url maybe not working so I deployed it to another app service but no luck.
Can anyone let me know where is the issue may be?
Thanks in advance.
I'm trying to use the new OpenAPI 2.0 setup in Acumatia 21R1 to create a PO Receipt. I've tested creating several other types of records (eg: StockItems) and virtually the same code works perfectly. This instance of Acumatica has several tenants but no branches.
I've also used this same code put pointed it to an instance of Acumatica that has one tenant and multiple branches, and as long as I set the branch it works fine.
When I run it I get "curyid can not be null". This leads me to believe that somehow it's not figuring out the branch or tenant correctly, but if I use the same login code I can pull data from those tenants just fine. I've also tried passing the json directly and including the curyid set to USD, but that has the same effect.
Any thoughts on what I am doing wrong?
private createPOR()
{
string baseURL = "https://acumatica.[good url goes here].com/AcumaticaPWS";
string strLogin = baseURL + "/entity/auth/login";
var client = new RestClient(strLogin);
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
string strBody = "{ \"name\": \"admin\", \"password\": \"[proper password]\", \"tenant\": \"PWS Milwaukee\", \"branch\": \"\"}";
request.AddJsonBody(strBody);
IRestResponse response = client.Execute(request);
txtResults.Text = response.Cookies.SingleOrDefault(x => x.Name == ".ASPXAUTH").Value.ToString();
RestResponseCookie sessionCookie = response.Cookies.SingleOrDefault(x => x.Name == ".ASPXAUTH");
// Create the new one for send the data.
string strItems = baseURL + "/entity/Default/20.200.001/PurchaseReceipt";
client = new RestClient(strItems);
request = new RestRequest(Method.PUT);
request.AddCookie(sessionCookie.Name, sessionCookie.Value);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
PurchaseReceipt theRec = new PurchaseReceipt{ Type = new StringValue { Value = "Receipt" },
VendorID = new StringValue { Value = "V1002" }
};
// BaseCurrencyID = new StringValue { Value = "USD" },
// CurrencyID = new StringValue { Value = "USD" }
request.AddJsonBody(JsonConvert.SerializeObject(theRec));
response = client.Execute(request);
txtResults.Text += Environment.NewLine + "Response" + response.StatusCode.ToString();
// Setup to log out.
string strLogout = baseURL + "/entity/auth/logout";
client = new RestClient(strLogout);
request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
response = client.Execute(request);
txtResults.Text += Environment.NewLine + response.StatusCode.ToString();
}
Like Samvel mentioned in the comments this issue is usually the result of not having provided the Branch during the login.
But once the Branch has been provided it still needs to be provided as a cookie for the other request down the line.
That cookie should have the name "UserBranch" with its value being an integer that should be returned from the login request.
I want to authorize an OAuth JSON Web Token granted by Azure Active Directory, and one thing I need to do is get more information about the application in the token's appId using the Microsoft Graph API.
Microsoft Graph API allows me to GET an app by its id via
https://graph.microsoft.com/beta/applications/{id}
, but NOT by its appId via
https://graph.microsoft.com/beta/applications/{appId}
The best way I see to use Microsoft Graph API to GET an app using its AppId is via a filter like so:
https://graph.microsoft.com/beta/applications?filter=appId eq '{appId}'
The above filter works just fine in the Microsoft Graph Explorer, but when calling the Graph API using a GET request using HttpUrlConnection, my request fails with HTTP Code 400 and message "Bad Request".
It's weird because using the exact same HttpUrlConnection to GET the full range of applications via
https://graph.microsoft.com/beta/applications
works just fine.
Is there something about the filter functionality that I can't use it in a Microsoft Graph API GET request? How should I get info on an app by its AppId?
Here is a snippet of the Java code I am using for my HttpURLConnection:
url = new URL(String.format("https://graph.microsoft.com/beta/applications?filter=appId eq '%s'", appId));
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Bearer " + result.getAccessToken());
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-Type", "application/json");
final int httpResponseCode = conn.getResponseCode();
if (httpResponseCode == 200 || httpResponseCode == 201) {
BufferedReader in = null;
final StringBuilder response;
try {
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
} finally {
in.close();
}
final JSONObject json = new JSONObject(response.toString());
return json.toString(4);
} else {
return String.format("Connection returned HTTP code: %s with message: %s",
httpResponseCode, conn.getResponseMessage());
}
In case someone else comes looking for this, if you are using the GraphServiceClient you can do this:
var appId = "some app id";
var response = await _graphClient.Applications
.Request()
.Filter($"appId eq '{appId}'")
.GetAsync();
var azureAddApplication = response.FirstOrDefault() ?? throw new ArgumentException($"Couldn't find App registration with app id {appId}");
In case someone is searching this... the API call should be done with the app's Object ID, not the app ID.
You should URLEncode the query parameters.
String url2=URLEncoder.encode("$filter=appId eq '{applicationId}'");
URL url = new URL("https://graph.microsoft.com/beta/applications?"+url2);
Recently I migrated MS Azure Translation API to V3 as V2 getting decomissioned this APRIL. Issue is when I wants to translate text containing some special characters like %,#,=,=> API respond 500 internal server error. Its unable to detect that characters.Is this bug with V3 azure translation API.
System.Object[] body = new System.Object[] { new { Text = #textToTranslate } };
var requestBody = JsonConvert.SerializeObject(body);
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(host + detectPath + "&" + requestBody);
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key);
client.Timeout = TimeSpan.FromMinutes(10);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var detetctContent = new StringContent(requestBody, Encoding.UTF8, "application/json");
var responseMessage = client.PostAsync(client.BaseAddress, detetctContent).Result; //here is the error comes have I missed something.
MS Azure translation API should recognized special characters as like V2 version.
I want to use setEntity in my code with HttpURLConnection but Android Studio
doesn't recognize setEntity in my code
and I added this code to my Gradle:
org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2
but didn't work for me
here is an image of my code
enter image description here
This has been deprecated so you can't use it anymore or basically not required.follow link to docs
To post data, you can write data (queryString) after the connection is opened.The data parameters can be formed as string then, you need to send your data in form of byte, below code converts the data into byte to send
String urlParameters = "param1=a¶m2=b¶m3=c";
byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;
String request = "http://example.com/index.php";
URL url = new URL(request);
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("charset", "utf-8");
conn.setRequestProperty("Content-Length", Integer.toString( postDataLength ));
conn.setUseCaches(false);
try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
wr.write( postData );
}