473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to handle REST API call for GET Verb

56
Dear pals,

I am newbie in RESTful services . I need to call a GET Verb in Server . I know 2 methods

1. Ajax Call

we can write it as

Expand|Select|Wrap|Line Numbers
  1.  
  2. $.ajax({
  3.          url: url, 
  4.          dataType: "html",
  5.          type: 'POST', 
  6.          data: "id="+id+"&type="+type, 
  7.          success: function(data){ 
  8.             //$("#content").html(data); 
  9.             alert(data);
  10.             $('table #sample-boxed-2-pagination th a').each(function(){
  11.                 //this.href = this.href.replace(sub_url, main_url);
  12.                 var value = this.href.split('?');
  13.                 //alert(value[0]);
  14.                 if(value[0]!=sub_url)
  15.                 {
  16.                   this.href = this.href.replace(value[0], sub_url);
  17.                 }
  18.       });
  19.          }
  20.  
  21.  
  22.       });         
  23. });
But I know it's not working in Cross domain scenario . Please advise a method to work same in all domains .

2. Using file_get_contents() function like

Expand|Select|Wrap|Line Numbers
  1. $response = file_get_contents('https://kkl.com/graph/call?parm1=9');
  2.  
  3.  
I know I can call POST verb using cURL as

Expand|Select|Wrap|Line Numbers
  1. $ch = curl_init();
  2.     curl_setopt($ch, CURLOPT_URL, "http://localhost/simple_rest_master/test");
  3.     curl_setopt($ch, CURLOPT_HEADER, 0);
  4.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5.     curl_setopt($ch, CURLOPT_POST, 1);
  6.     $data = array(
  7.         'username' => 'foo',
  8.         'password' => 'bar'
  9.     );
  10.     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  11.     $contents = curl_exec($ch);
  12.     curl_close($ch);
  13.     echo $contents;  // manipulate response
  14.  
Do you can advise the syntax of GET call using cURL ?

Waiting your fast reply

Thanks,

Anes
Sep 28 '13 #1
0 1150

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jkdufair | last post by:
I'm looking for advice. I have been playing with Konfabulator which embeds SpiderMonkey (apparently using the JavaScript 1.5 api) for scripting "widgets" - various bits of eye candy that sit on...
0
by: Up2 | last post by:
I'm trying to call a C# dll I have made in Visual Studio .net. I'm pretty new to C# and makings of dll files. I code in C5/XAL daily. I have been told that the XAL language can't call C#, VB...
1
by: Fei Yuan | last post by:
Please forgive me re-posting this question since I wasn't clear in my original post. --------> Starting an external process needs to pass it a ProcessStartInfo() object. ProcessStartInfo has a...
5
by: The Real Andy | last post by:
Sorry if this question sounds stupid, its early days for me when it comes to c# and com interop. I have a method imported from Win Media PLayer SDK, IWMPPluginUI:DisplayPropertyPage, like so: ...
2
by: Cy Huckaba | last post by:
I am writing a program that will search xml files for some of our dev team here and list the files in a list box. I would like to be able to double-click on the file name and have the file open...
2
by: Gary Wessle | last post by:
Hi I need help organizing this program in the right way. I included the code below which compiles and runs and gives the desired effect to a certain point, but I don't know what the next step...
3
by: qfchen | last post by:
Hi, I have a problem to call a richText control's invoke from other window form while program background work. however if I implement the background work under the same window form as the control,...
7
by: Shraddha | last post by:
What is exactly a handle to an object????Is it same as reference....
0
by: fredd00 | last post by:
Hi I have a web service located at /service/test.asmx my web app is secured by form authentication when i call my service i get redirected to login.aspx?returnurl = .../ service/test.asmx ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.