Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

problem while REST call for Vanity URL using C-URL

 
Greenhorn
Posts: 13
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a Custom REST tool in which we write REST automations (like postman).
It differs from postman such that we can login in our site and save login details and use them further tests
right now tool works for the normal login urls called from curl
next hurdle I'm facing is how to login using Vanity Url we have for our site
via postman its working fine. but via tool its not working and since I'm new to curl. I dont know what all configurations and parameters I'll require to make it work using vanity URL


function getUrlContent($url, $type, $data, $postBody, $file) {
$ch = curl_init();
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) ";
curl_setopt_array($ch, array(
CURLOPT_USERAGENT => $agent,
CURLOPT_VERBOSE => 0,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_AUTOREFERER => TRUE
));

if (strpos($url, "https://";) !== false) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
}

$url = sprintf("%s?%s", $url, http_build_query($data));

$headers = array("Content-type: application/json; charset=UTF-8");
foreach ($data as $key => $value) {
$headers[] = "$key: $value";
}

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_URL, $url);

$content = curl_exec($ch);
$result = array();

$responseContentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$responseHeaders = curl_getinfo($ch);
$result['responseHeaders'] = $responseHeaders;
$result['responseContentType'] = $responseContentType;

if (strpos($content, "{") !== false || strpos($content, "[") !== false) {
if ($responseContentType == 'application/json') {
$output = json_decode($content);
$result['output'] = $output;
} else if ($responseContentType == 'application/zip') {
$url = urldecode($url);
$url = substr($url, 0, strpos($url, "?") - 1);
$filename = substr($url, strrpos($url, "/") + 1);
$result['filename'] = $filename . ".zip";
file_put_contents("download" . DIRECTORY_SEPARATOR . $result['filename'], $content);
$result['output'] = "download/" . $result['filename'];

} else if ($responseContentType == 'text/plain') {
$result['output'] = $content;
} else {
$result['output'] = 'Some error occured in service invocation';
}
} else {
$result['output'] = $content;
}
curl_close($ch);
return json_encode($result);
}

if (isset($_GET['url']) and isset($_GET['type'])) {
if (isset($_GET['data'])) {
$data = json_decode($_GET['data'], true);
$url = $_GET['url'];
$type = $_GET['type'];
$postBody = '';
if (isset($_GET['postBody'])) {
$postBody = trim($_GET['postBody']);
}
$file = null;
if (isset($_GET['file'])) {
$file = $_GET['file'];
}
echo getUrlContent($url, $type, $data, $postBody, $file);
}
}


These are current curl setting with which normal REST calls are working

observations from attached screenshots while performing login from POSTMAN
Note: To login I use username/password and site-name which changes according to tenant used.
When I do REST call using normal url he response headers I get are 11 and while vanity I get 19 (does that mean I need to pass more info for vanity url?) If so then what will it be?
normalurl.PNG
[Thumbnail for normalurl.PNG]
REST call using normal URL
vanityurl.PNG
[Thumbnail for vanityurl.PNG]
REST call using vanity URL
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic