All Entries Tagged With: "request"
Send a webrequest and display webresponse along with headers in C#
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<script language="C#" runat="server">
void btnSubmit_OnClick(Object source, EventArgs e)
{
// Create a WebRequest
WebRequest wrRequest;
wrRequest = WebRequestFactory.Create(txtURL.Text);
// Get the Response from the Request
WebResponse wrResponse = wrRequest.GetResponse();
// Display the Request headers
lblHTML.Text = "<b>Request Header Information:</b><br>";
foreach (String strHeader in wrRequest.Headers)
lblHTML.Text += [...]
Perform a HTTP POST Request with the HttpClient in Android
HTTP POST calls are made with the HttpClient by calling the execute() method of the HttpClient with an instance of HttpPost. We should pass URL-encoded name/value form parameters as part of the HTTP request.
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class TestHttpPost
{
public String executeHttpPost() throws Exception {
[...]
Example of HTTP GET Request using HttpClient in Android
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class TestHttpGet {
public void executeHttpGet() throws Exception {
BufferedReader in = null;
try {
HttpClient client = new [...]
Example of a SOAP request
This example sends a request to the United States National Weather Service for forecast data that the site has available through SOAP. The entire message is encapsulated within the section, which contains the SOAP body inside the section.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<namesp1:NDFDgenByDay
xmlns:namesp1="http://weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl">
<latitude xsi:type="xsd:float">44.52</latitude>
<longitude xsi:type="xsd:float">-89.58</longitude>
<startDate xsi:type="xsd:string">2005-04-23</startDate>
<numDays xsi:type="xsd:int">5</numDays>
<format xsi:type="xsd:string">12 hourly</format>
</namesp1:NDFDgenByDay>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Request and Display Basic Viewer Data in Open Social
Step 1. Request data:
a. Create DataRequest object by calling opensocial.newDataRequest.
b. For each request you wish to make, create it using one of the opensocial.new* methods.
c. For each piece of data you want to request, add a request via DataRequest.add(request).
d. [...]
Simple HTTP requestor in c#
The WebRequest class in .NET includes a member named GetResponse that sends a request to the address specified by the Uniform Resource Locator (URL).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace WRApp
{
class Program
{
static void Main(string[] args)
{
WebRequest req = WebRequest.Create ("http://www.w3mentor.com");
WebResponse resp = req.GetResponse();
StreamReader reader [...]
View source of webpage using PHP
To read the contents of a webpage from a URL and manipulate it as file, we can use the fopen() php function, which supports the capability of opening URLs.
<?php
$url = "http://w3mentor.com";
$fp = @fopen($url, ‘r’)
or die("Cannot Open $url via Get method");
while ($line = @fgets($fp, 1024)) {
$contents .= $line;
}
fclose($fp);
?>
PHP Request variables
argv
argv is defined as an array of arguments passed to the script on the command line. When the PHP script is called using the GET method, argv will contain any query string information.
argc
argc is defined as the number of command-line parameters passed to the script.
PHP_SELF
PHP_SELF is defined as the current executing PHP script. [...]
Determine request type in PHP
The $_SERVER['REQUEST_METHOD'] variable can be used to determine whether the request was submitted with the get or post method.
In the example below, If the get method was used, we print the form. If the post method was used, we process the form.
<?php if ($_SERVER[’REQUEST_METHOD’] == ‘GET’) { ?>
<form action="<?php echo $_SERVER[’SCRIPT_NAME’] ?>" method="post">
What is your [...]
Create an XML-RPC Request with xmlrpc_encode_request
The process to create an XML-RPC request can be broken up into individual steps:
Serialize the PHP data into XML-RPC format
Create an XML-RPC request by combining HTTP headers and serialized data
Make the call to the service
The PHP function xmlrpc_encode_request can be used to serialize data and it creates the entire XML-RPC request call starting with the [...]