Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to send a request and receive the text from the HTTP response?

Posted on 2011-04-26
11
Medium Priority
?
336 Views
Last Modified: 2012-08-14
I have an URL to send and receive some text from the HTTP response. How can I send and receive the response from http?

Basically, I need to grab some texts from the response on the url send.
0
Comment
Question by:Loganathan Natarajan
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 22

Expert Comment

by:Om Prakash
ID: 35472841
<?php
$r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
try {
    echo $r->send()->getBody();
} catch (HttpException $ex) {
    echo $ex;
}
?>
http://php.net/manual/en/function.httprequest-send.php
0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 35472852
thanks, just a thought after going through cURL... can i use cURL to do this?
0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 35472953
What I need is specifically,  from this URl, I need to grad the flash object ...
http://www.saynow.com/playMsg.html?ak=Q1hwbUJsMTJiNTZJdVlZaVpGd1BmUT09
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 7

Expert Comment

by:Vimal DM
ID: 35473216
Hai,

It is easy in 'Ajax' way of doing things,

1) Having this file included zxml.src.js
2) Can search for the httpresponse and httprequest online

it is very simple implementation


                         or

There is also another way of making the ajax in the same way,but not including the file called zxml.src.js


Try
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35475416
The code snippet contains the HTML returned from http://www.saynow.com/playMsg.html?ak=Q1hwbUJsMTJiNTZJdVlZaVpGd1BmUT09

Is the information you want in there?  If so, please point it out and we might be able to show you how to capture it.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <meta name="title" content="Voice Message from speak2tweet " /> 
    <meta name="description" content="Sent via SayNow on 04/25/11 07:34 AM">
    <meta name="medium" content="mult">
    <link rel="video_src" href="http://www.saynow.com/flash/fb_player.swf?aikey=Q1hwbUJsMTJiNTZJdVlZaVpGd1BmUT09&autoplay=1&url=http://my.saynow.com&display_name=speak2tweet &icon_url=http://asset.saynow.com/images/defaultPic.jpg&sent_date=04/25/11 07:34 AM"/>
    <meta name="video_height" content="40" /> 
    <meta name="video_width" content="400" /> 
    <meta name="video_type" content="application/x-shockwave-flash" />
    <link rel="image_src" href="/images/default_pic.jpg"/>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Pragma-directive" content="no-cache" />
<meta http-equiv="Cache-directive" content="no-cache" />




  <title>Saynow: Voice Message from speak2tweet </title>


<!--[if IE 6]><link href="/stylesheets/sn/common/ie6only.css?1295653465" media="screen" rel="stylesheet" type="text/css" /><![endif]-->
<!--[if IE 7]><link href="/stylesheets/sn/common/ie7only.css?1295653465" media="screen" rel="stylesheet" type="text/css" /><![endif]-->
<!--[if IE]><link href="/stylesheets/sn/common/ie.css?1295653465" media="screen" rel="stylesheet" type="text/css" /><![endif]-->
<link rel="Shortcut Icon" href="/favicon.ico" />


    <link href="/stylesheets/cache/play_message_packaged.css?1296371933" media="screen" rel="stylesheet" type="text/css" />
    <script src="/javascripts/cache/play_message_packaged.js?1296371929" type="text/javascript"></script>
    


  <script type="text/javascript">
    
    $.fn.track.defaults.skip_internal = false;
    $.trackPage("UA-664032-1", { 
      
        page_url: "/play_message/jan25/Q1hwbUJsMTJiNTZJdVlZaVpGd1BmUT09",
      
      onload: false
    });
    $(function() {
      $.setVarEvent("not");
    });
 </script>


    <script type="text/javascript">
  $(document).ready( function(){
  $('.topRounded').corners("top");
  $('.bottomRounded').corners("bottom");
  $('.rounded').corners();
  });
</script>

    <script type="text/javascript" charset="utf-8"  src="http://bit.ly/javascript-api.js?version=latest&login=saynowweb&apiKey=R_bed0bb54135ce53d7d170a3e62e88718"></script>

    <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
  </head>
  <body>
    <script src="/javascripts/AC_RunActiveContent-1.7.js?1295653336" type="text/javascript"></script>

<script type="text/javascript">
AC_FL_RunContent(
  'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
  'width', '1',
  'height', '1',
  'src', '/flash/miniplayer',
  'quality', 'high',
  'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
  'align', 'middle',
  'id', 'miniplayer',
  'bgcolor', '#ffffff',
  'name', 'miniplayer',
  'allowFullScreen', 'false',
  'allowScriptAccess','sameDomain',
  'movie', '/flash/miniplayer',
  "FlashVars", "url=http://my.saynow.com"
);
</script>

<script src="/javascripts/sn/miniplayer.js?1295653335" type="text/javascript"></script>

    <div id="container">
      <div class="clear"></div>
      <div id="header">
        <div id="topnav">
<div class="links">
    
    <a href="http://www.saynow.com/info/learn_more">Learn More</a>
    <img src="/images/symbol_dot.gif" alt="dot" />
    <a href="/info/customers">Browse People</a>

    <img src="/images/symbol_dot.gif" alt="dot" />
    <a href="http://blog.saynow.com">Blog</a>
    <img src="/images/symbol_dot.gif" alt="dot" />
    
      <a href="http://www.saynow.com/sign_up.html">Sign Up</a>
      <img src="/images/symbol_dot.gif" alt="dot" />
      <strong><a href="http://www.saynow.com/account/login">Login</a></strong>
    
</div>

</div>
<div class="logo">
  <a href="/"><img src="/images/logo_50.png" class="logo" alt="SayNow" /></a>
</div>

      </div>
      <div class="clear"></div>
      <div id="profile">
        <!-- TODO  -->
<style type="text/css" media="screen">
.msgloading {
  padding-left:0px;
}
</style>

<script type="text/javascript" charset="utf-8">

$(function() {
  $('#embedText, #embedUrl').click(function() {
    $(this).focus();
    $(this).select();
  });
  $(".msgs-container").each(function() {
    $('#outgoingmsgs-container').
      prepend("<div class='msgloading'><div style='padding:1px'>Loading...</div></div>");
    $('#outgoingmsgs-container').
      load('/play_message/messages/' + 'jan25',
         function(response, status) {
           $('#outgoingmsgs-container div.msgloading').remove();
         });
  });
  var sender = "jan25";
  $.trackEvent("play_message/" + sender, "load", "aikey", "Q1hwbUJsMTJiNTZJdVlZaVpGd1BmUT09");
})

function trackFbConnect(id, aikey) {
  alog({'event':'install_playmsg_aikey', 'event_value':aikey}, function(){window.location = "http://apps.facebook.com/saynowtalk/users/" + id + "?r=playmsg"});
}
</script>


<div id="maincontent" style="width:960px;">

  <div id="title" class="topRounded">
    <h1>Message</h1>
  </div>

  <div id="main">

  <div id="msgsidebar">


  </div>

        <div id="content_item">
        <div class="userIcon"><a href="http://www.saynow.com/jan25"><img alt="Default_pic" src="/images/default_pic.jpg" /></a></div>
        <h2>Voice Message from <span class='username'><a href="http://www.saynow.com/jan25">speak2tweet </a></span></h2>
        <p class="msgMeta">

    04/25/11 07:34 AM, 04:05
        </p>

        <div class="audiowidget">
    
      <embed src='http://www.saynow.com/flash/sentplayer3.swf' quality="high" FlashVars="itemId=Q1hwbUJsMTJiNTZJdVlZaVpGd1BmUT09&autoplay=0&duration=04:05&url=http://my.saynow.com" bgcolor="#ffffff" wmode="opaque" width="320" height="65" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>

    
        </div>

        <div class="msgactions">
        <span class="action">
        
        
                </span>

        <span class="action">
        
        </span>
        </div>


    <div class="clear"></div>
    <div class="clear"></div>
  </div>
 </div>
</div>

      </div>
    </div>
    <div class="clear"></div>
    <div id="footer">
      <div class="info">
  <p>
    <a href="http://www.saynow.com/info/about">About Us</a> |
    <a href="http://www.saynow.com/info/terms">Terms of Service</a> |
    <a href="http://www.saynow.com/info/privacy">Privacy Policy</a> |
	<a href="http://saynow.zendesk.com/" title="SayNow Support">Help and Support</a>

  </p>
  <p class="disclaimer">Text message notification works on most U.S. carriers. SayNow is free, but your cell phone carrier may charge you for receiving text messages or for long distance calls depending on the type of plan you have. To stop receiving text messages, text STOP to 729669 (SAYNOW). For help, text HELP.</p>
</div>

    </div>
    <script type="text/javascript">  FB.init("4da2c0f44542441be79550ef104a6644", "/xd_receiver.html"); </script>
  </body>
</html>

Open in new window

0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35475962
You only need to make AJAX request, I recommend you to use jQuery AJAX:
http://api.jquery.com/jQuery.ajax/

You might also use the normal way (without jQuery):
http://www.tizag.com/ajaxTutorial/ajax-javascript.php
0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 600 total points
ID: 35476020
If you want to make the request using PHP, you will have to use cURL:
http://php.net/manual/en/book.curl.php

Example:
<?
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com'); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$data = curl_exec(); 
curl_close($ch); 
?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35476110
receive some text from the HTTP response

I guess the question I have is, what do you really want to retrieve?  Are you looking for text in the HTML string or looking for the HTTP response headers?  Let us know, thanks.
0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 35480761
@ Ray ... thanks for your inputs and clarification...

Yes, I am looking for text to parse from the HTML Source. I like to parse only the EMBED tag from the source. How can I retrieve?

@ Medo3337
I am trying in this way and like to parse only the EMBED tag. how to do further?
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1400 total points
ID: 35482998
Try this.  On my server at http://www.laprbass.com/RAY_temp_logudotcom.php

HTH, ~Ray
<?php // RAY_temp_logudotcom.php
error_reporting(E_ALL);

// GET DATA FROM THE WEB SITE AND ISOLATE THE PART WE WANT TO PROCESS
$url = 'http://www.saynow.com/playMsg.html?ak=Q1hwbUJsMTJiNTZJdVlZaVpGd1BmUT09';
$htm = file_get_contents($url);
$htm = strip_tags($htm, '<embed>');
$htm = trim(preg_replace('/\s\s+/', ' ', $htm));
$emb = strpos($htm, '<embed ') + strlen('<embed ');
$end = strpos($htm, '</embed');
$dat = substr($htm, $emb, $end-$emb);

// SHOW THE STRING FROM THE EMBED TAG
var_dump($dat);

Open in new window

0
 
LVL 36

Author Closing Comment

by:Loganathan Natarajan
ID: 35489434
thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question