message
[mdref/mdref-http] / http / Message / setRequestUrl.md
1 # http\Message http\Message::setRequestUrl(string $url)
2
3 Set the request URL of the message.
4 See http\Message::getRequestUrl() and http\Message::setRequestMethod().
5
6 ## Params:
7
8 * string $url
9 The request URL.
10
11 ## Returns:
12
13 * http\Message, self.
14 * false, if the message was not of type request.
15
16 ## Notices:
17
18 * E_MESSAGE_TYPE, if the message is not of type request.
19
20 ## Warnings:
21
22 * E_INVALID_PARAM, if the url is of zero length.
23
24 ## Example:
25
26 > **Note:** The request URL in a request message usually only consists of the path and the querystring.
27
28 <?php
29 $m = new http\Message;
30 $m->setType(http\Message::TYPE_REQUEST);
31 $m->setRequestMethod("GET");
32 $m->setRequestUrl("http://foo.bar/baz?q");
33 echo $m;
34 ?>
35
36 Yields:
37
38 GET http://foo.bar/baz?q HTTP/1.1
39
40 Maybe you did not really expect this, so let's try this:
41
42 <?php
43 $m = new http\Message;
44 $u = new http\Url("http://foo.bar/baz?q");
45 $m->setType(http\Message::TYPE_REQUEST);
46 $m->setRequestMethod("GET");
47 $m->setRequestUrl($u->path ."?". $u->query);
48 $m->setHeader("Host", $u->host);
49 echo $m;
50 ?>
51
52 Yields:
53
54 GET /baz?q HTTP/1.1
55 Host: foo.bar