package ru.open; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static void main(String[] args) throws IOException { String domain = "DOMAIN"; String username = "LOGIN"; String password = "PASSWORD"; String scheme = "https"; String crmUrl = "URL"; String orgName = "ORG_NAME"; String url = String.format("%s://%s%s%s:%s@%s/%s", scheme, domain, "%5C", username, password, crmUrl, orgName); String actionName = "new_CustomAction"; // then use https you need to store certificate in cacerts before call CRM service // to avoid "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target" exception // see: https://stackoverflow.com/questions/9619030/resolving-javax-net-ssl-sslhandshakeexception-sun-security-validator-validatore for details if (scheme == "https") { System.setProperty("javax.net.ssl.trustStore", "C:\\Program Files (x86)\\Java\\jre1.8.0_144\\lib\\security\\cacerts"); } String reqXML = "" + "" + "" + "" + "" + "" + "" + "" + "data" + "" + "test" + "" + "" + "" + "" + "" + actionName + "" + "" + "" + "" + ""; jcifs.Config.registerSmbURLHandler(); URL urlRequest = new URL(url + "/XRMServices/2011/Organization.svc/web"); HttpURLConnection conn = (HttpURLConnection)urlRequest.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); conn.setRequestProperty("Accept", "application/xml, text/xml, */*"); conn.setRequestProperty("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute"); conn.setRequestProperty("Content-Length", String.valueOf(reqXML.length())); conn.setDoOutput(true); conn.setDoInput(true); StringBuilder response = new StringBuilder(); try { OutputStream reqStream = conn.getOutputStream(); reqStream.write(reqXML.getBytes("UTF-8")); InputStream stream = conn.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(stream)); String str; while ((str = in.readLine()) != null) { response.append(str); } in.close(); System.out.println(response); } catch(Exception err) { System.out.println(err); } } }