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 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4429 | ||
| 2634 | 6개월 전 | 611 | ||
| 2633 | 6개월 전 | 602 | ||
| 2632 |
|
7개월 전 | 511 | |
| 2631 | 7개월 전 | 572 | ||
| 2630 |
세르반데스
|
7개월 전 | 538 | |
| 2629 | 7개월 전 | 729 | ||
| 2628 | 7개월 전 | 412 | ||
| 2627 | 7개월 전 | 421 | ||
| 2626 |
이슈DEV
|
7개월 전 | 643 | |
| 2625 |
welcome
|
7개월 전 | 648 | |
| 2624 |
이슈DEV
|
7개월 전 | 449 | |
| 2623 | 7개월 전 | 409 | ||
| 2622 | 7개월 전 | 496 | ||
| 2621 | 7개월 전 | 354 | ||
| 2620 |
|
7개월 전 | 371 | |
| 2619 | 7개월 전 | 479 | ||
| 2618 | 7개월 전 | 466 | ||
| 2617 | 7개월 전 | 556 | ||
| 2616 | 8개월 전 | 680 | ||
| 2615 | 8개월 전 | 585 | ||
| 2614 | 8개월 전 | 413 | ||
| 2613 |
바닐라코드
|
8개월 전 | 732 | |
| 2612 | 8개월 전 | 596 | ||
| 2611 | 8개월 전 | 733 | ||
| 2610 | 8개월 전 | 970 | ||
| 2609 | 8개월 전 | 509 | ||
| 2608 | 8개월 전 | 655 | ||
| 2607 | 8개월 전 | 632 | ||
| 2606 | 8개월 전 | 578 | ||
| 2605 | 8개월 전 | 604 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기