php XML 송신 및 수신 samlple
send.php
<?php
/*--------------샘플 XML ---------------
<?xml version='1.0' encoding='UTF-8' ?>
<contents>
<userid>deuxign</userid>
<point>91035</point>
</contents>
--------------------------------------*/
// XML 데이터 생성 - 페이지 인코딩이 euc-kr이라 iconv로 UTF-8 형식으로 변환
$member_info_xml = '<'.chr(63).'xml version="1.0" encoding="UTF-8" '.chr(63).'>'.chr(10);
$member_info_xml .= '<contents>'.chr(10);
$member_info_xml .= '<userid>deuxign</userid>'.chr(10);
$member_info_xml .= '<point>91035</point>'.chr(10);
$member_info_xml .= '</contents>'.chr(10);
// fsock으로 POST 전송
$host = 'www.abc.co.kr'; //'www.example.com';
$path = '/xml/receive.php';
$xmlData = $member_info_xml;
// 헤더를 설정해서 POST로 전송
$fp = fsockopen($host, '80', $errno, $errstr, 30);
if($fp)
{
$header = "POST ".$path." HTTP/1.1\r\n";
$header .= "Host: ".$host."\r\n";
$header .= "User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\n";
$header .= "Content-type: text/html\r\n";
$header .= "Content-length: ".strlen($xmlData)."\r\n\r\n";
$header .= $xmlData."\r\n";
fputs($fp, $header.$xmlData."\r\n\r\n");
while(!feof($fp))
{
$result .= fgets($fp, 1024);
}
fclose($fp);
echo $result; // 결과를 출력한다.
}
else
{
echo "$errstr ($errno)<br />\n";
}
?>
receive.php
<?php
ini_set("always_populate_raw_post_data", "true");
$receive_xml = file_get_contents('php://input');
/*--------------------------------------
* XML Parse - simple_XML
----------------------------------------*/
$dom = new DOMDocument;
$dom->loadXML($receive_xml);
if (!$dom) {
echo 'Error while parsing the document';
exit;
}
$XML = simplexml_import_dom($dom);
/* $XML 은 이런 형태를 가진다.
SimpleXMLElement Object
(
[userid] => deuxign
[point] => 91035
)
*/
// 받은 데이터 처리
// UTF-8을 euc-kr로 변경
$userid= iconv('UTF-8','EUC-KR',$XML->userid);
$point= iconv('UTF-8','EUC-KR',$XML->point);
echo "success";
?>
댓글 1개
이건 어디다 쓰는건가요?
기존에 있던 rss.php 하고 뭐가 다르죠?
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 25 |
|
12년 전 | 5921 | |
| 24 | 12년 전 | 7365 | ||
| 23 | 12년 전 | 5220 | ||
| 22 |
JMoon
|
12년 전 | 6240 | |
| 21 |
오늘도망했다
|
12년 전 | 13474 | |
| 20 | 12년 전 | 4315 | ||
| 19 | 12년 전 | 8041 | ||
| 18 | 12년 전 | 6507 | ||
| 17 | 12년 전 | 5410 | ||
| 16 | 12년 전 | 6126 | ||
| 15 | 12년 전 | 5607 | ||
| 14 | 12년 전 | 9220 | ||
| 13 | 12년 전 | 8192 | ||
| 12 | 12년 전 | 4943 | ||
| 11 | 12년 전 | 7258 | ||
| 10 |
|
12년 전 | 8953 | |
| 9 | 12년 전 | 7547 | ||
| 8 | 12년 전 | 8123 | ||
| 7 | 12년 전 | 7321 | ||
| 6 | 12년 전 | 7450 | ||
| 5 | 12년 전 | 7370 | ||
| 4 | 12년 전 | 7458 | ||
| 3 | 12년 전 | 6948 | ||
| 2 | 12년 전 | 5796 | ||
| 1 | 12년 전 | 12116 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기