得到了一个具有 post 函数的类,该函数应该将大量参数存储到 db。问题是,我无法从请求正文中获取发送参数。我测试了几乎所有的组合:
- 添加 request_data 作为结束参数 - > 不工作(如果我放弃它说 ZEITSTEMPEL 丢失)
- 设置不带 NULL 的参数(必需)-> 不工作
- 只取两个参数(认为太多了)-> 不工作
- 试图通过 $request_data['ZEITSTEMPEL'] 获取参数 -> 不工作(显示为空)
我用restler的最新版本(今天)尝试了所有这些,并通过restler api和restcliebt(firefox插件)发布。
Firefox 插件通过我无法解决的其他错误(添加的内容类型 json 不起作用)
{
"error": {
"code": 403,
"message": "Forbidden: Content type application/JSON is not supported."
}
}
我有点坚持这个希望可以提供帮助。这是我的代码:
class messprotokoll {
/**
* save messprotokoll
*
* one could save a messprotokoll
* result is the status
* in JSON format
*
*
* @param string $ZEITSTEMPEL {@from body} comment
* @param string $ID_MESSPROTOKOLL {@from body} comment
* @param string $ID_GERAET {@from body} comment
* @param string $D_229 {@from body} comment
* @param string $D_230 {@from body} comment
* @param string $TYP {@from body} comment
* ....continues...
* @throws 400 No value given for id
* @return json
*
*/
function post($ZEITSTEMPEL=NULL,$ID_MESSPROTOKOLL=NULL,$ID_GERAET=NULL,$D_229=NULL,$D_230=NULL,$TYP=NULL,$D_226=NULL,$D_227=NULL,$D_228=NULL,$D_223=NULL,$D_224=NULL,$D_225=NULL,$D_220=NULL,$D_221=NULL,$D_222=NULL,$D_217=NULL,$D_218=NULL,$D_219=NULL,$D_214=NULL,$D_215=NULL,$D_216=NULL,$D_211=NULL,$D_212=NULL,$D_213=NULL,$D_208=NULL,$D_209=NULL,$D_210=NULL,$D_205=NULL,$D_206=NULL,$D_207=NULL,$D_202=NULL,$D_203=NULL,$D_204=NULL,$D_199=NULL,$D_200=NULL,$D_201=NULL,$D_196=NULL,$D_197=NULL,$D_198=NULL,$D_193=NULL,$D_194=NULL,$D_195=NULL,$D_190=NULL,$D_191=NULL,$D_192=NULL,$D_187=NULL,$D_188=NULL,$D_189=NULL,$D_184=NULL,$D_185=NULL,$D_186=NULL,$D_181=NULL,$D_182=NULL,$D_183=NULL,$D_178=NULL,$D_179=NULL,$D_180=NULL,$D_175=NULL,$D_176=NULL,$D_177=NULL,$D_172=NULL,$D_173=NULL,$D_174=NULL,$D_169=NULL,$D_170=NULL,$D_171=NULL,$D_166=NULL,$D_167=NULL,$D_168=NULL,$D_163=NULL,$D_164=NULL,$D_165=NULL,$D_160=NULL,$D_161=NULL,$D_162=NULL,$D_157=NULL,$D_158=NULL,$D_159=NULL,$D_154=NULL,$D_155=NULL,$D_156=NULL,$D_151=NULL,$D_152=NULL,$D_153=NULL,$D_148=NULL,$D_149=NULL,$D_150=NULL,$D_145=NULL,$D_146=NULL,$D_147=NULL,$D_142=NULL,$D_143=NULL,$D_144=NULL,$D_139=NULL,$D_140=NULL,$D_141=NULL,$D_136=NULL,$D_137=NULL,$D_138=NULL,$D_133=NULL,$D_134=NULL,$D_135=NULL,$D_130=NULL,$D_131=NULL,$D_132=NULL,$D_127=NULL,$D_128=NULL,$D_129=NULL,$D_124=NULL,$D_125=NULL,$D_126=NULL,$D_121=NULL,$D_122=NULL,$D_123=NULL,$D_118=NULL,$D_119=NULL,$D_120=NULL,$D_115=NULL,$D_116=NULL,$D_117=NULL,$D_112=NULL,$D_113=NULL,$D_114=NULL,$D_109=NULL,$D_110=NULL,$D_111=NULL,$D_106=NULL,$D_107=NULL,$D_108=NULL,$D_103=NULL,$D_104=NULL,$D_105=NULL,$D_100=NULL,$D_101=NULL,$D_102=NULL,$D_097=NULL,$D_098=NULL,$D_099=NULL,$D_094=NULL,$D_095=NULL,$D_096=NULL,$D_091=NULL,$D_092=NULL,$D_093=NULL,$D_088=NULL,$D_089=NULL,$D_090=NULL,$D_085=NULL,$D_086=NULL,$D_087=NULL,$D_082=NULL,$D_083=NULL,$D_084=NULL,$D_079=NULL,$D_080=NULL,$D_081=NULL,$D_076=NULL,$D_077=NULL,$D_078=NULL,$D_073=NULL,$D_074=NULL,$D_075=NULL,$D_070=NULL,$D_071=NULL,$D_072=NULL,$D_067=NULL,$D_068=NULL,$D_069=NULL,$D_064=NULL,$D_065=NULL,$D_066=NULL,$D_061=NULL,$D_062=NULL,$D_063=NULL,$D_058=NULL,$D_059=NULL,$D_060=NULL,$D_055=NULL,$D_056=NULL,$D_057=NULL,$D_052=NULL,$D_053=NULL,$D_054=NULL,$D_049=NULL,$D_050=NULL,$D_051=NULL,$D_046=NULL,$D_047=NULL,$D_048=NULL,$D_043=NULL,$D_044=NULL,$D_045=NULL,$D_040=NULL,$D_041=NULL,$D_042=NULL,$D_037=NULL,$D_038=NULL,$D_039=NULL,$D_034=NULL,$D_035=NULL,$D_036=NULL,$D_031=NULL,$D_032=NULL,$D_033=NULL,$D_028=NULL,$D_029=NULL,$D_030=NULL,$D_025=NULL,$D_026=NULL,$D_027=NULL,$D_022=NULL,$D_023=NULL,$D_024=NULL,$D_019=NULL,$D_020=NULL,$D_021=NULL,$D_016=NULL,$D_017=NULL,$D_018=NULL,$D_013=NULL,$D_014=NULL,$D_015=NULL,$D_010=NULL,$D_011=NULL,$D_012=NULL,$D_007=NULL,$D_008=NULL,$D_009=NULL,$D_004=NULL,$D_005=NULL,$D_006=NULL,$D_001=NULL,$D_002=NULL,$D_003=NULL,$PROTOKOLLNR=NULL,$GERAETENR=NULL,$PRUEFER=NULL,$UEBERTRAGUNGSDATEN=NULL,$ID_GERAET2=NULL,$ID_GERAET3=NULL,$ID_GERAET4=NULL,$GERAETENR2=NULL,$GERAETENR3=NULL,$GERAETENR4=NULL,$Bemerkungen=NULL,$Durchgefuehrte_Arbeiten=NULL,$ID_Techniker=NULL,$request_data=NULL) {
//function post($ID_MESSPROTOKOLL,$ZEITSTEMPEL=NULL){
echo "Request:".$request_data['ZEITSTEMPEL']; //this is NULL??
$sql= "INSERT INTO dbo.MESSPROTOKOLL(ZEITSTEMPEL,ID_MESSPROTOKOLL,ID_GERAET,D_229,D_230,TYP,D_226,D_227,D_228,D_223,D_224,D_225,D_220,D_221,D_222,D_217,D_218,D_219,D_214,D_215,D_216,D_211,D_212,D_213,D_208,D_209,D_210,D_205,D_206,D_207,D_202,D_203,D_204,D_199,D_200,D_201,D_196,D_197,D_198,D_193,D_194,D_195,D_190,D_191,D_192,D_187,D_188,D_189,D_184,D_185,D_186,D_181,D_182,D_183,D_178,D_179,D_180,D_175,D_176,D_177,D_172,D_173,D_174,D_169,D_170,D_171,D_166,D_167,D_168,D_163,D_164,D_165,D_160,D_161,D_162,D_157,D_158,D_159,D_154,D_155,D_156,D_151,D_152,D_153,D_148,D_149,D_150,D_145,D_146,D_147,D_142,D_143,D_144,D_139,D_140,D_141,D_136,D_137,D_138,D_133,D_134,D_135,D_130,D_131,D_132,D_127,D_128,D_129,D_124,D_125,D_126,D_121,D_122,D_123,D_118,D_119,D_120,D_115,D_116,D_117,D_112,D_113,D_114,D_109,D_110,D_111,D_106,D_107,D_108,D_103,D_104,D_105,D_100,D_101,D_102,D_097,D_098,D_099,D_094,D_095,D_096,D_091,D_092,D_093,D_088,D_089,D_090,D_085,D_086,D_087,D_082,D_083,D_084,D_079,D_080,D_081,D_076,D_077,D_078,D_073,D_074,D_075,D_070,D_071,D_072,D_067,D_068,D_069,D_064,D_065,D_066,D_061,D_062,D_063,D_058,D_059,D_060,D_055,D_056,D_057,D_052,D_053,D_054,D_049,D_050,D_051,D_046,D_047,D_048,D_043,D_044,D_045,D_040,D_041,D_042,D_037,D_038,D_039,D_034,D_035,D_036,D_031,D_032,D_033,D_028,D_029,D_030,D_025,D_026,D_027,D_022,D_023,D_024,D_019,D_020,D_021,D_016,D_017,D_018,D_013,D_014,D_015,D_010,D_011,D_012,D_007,D_008,D_009,D_004,D_005,D_006,D_001,D_002,D_003,PROTOKOLLNR,GERAETENR,PRUEFER,UEBERTRAGUNGSDATEN,ID_GERAET2,ID_GERAET3,ID_GERAET4,GERAETENR2,GERAETENR3,GERAETENR4,Bemerkungen,Durchgefuehrte_Arbeiten,ID_Techniker) VALUES(:ZEITSTEMPEL,:ID_MESSPROTOKOLL,:ID_GERAET,:D_229,:D_230,:TYP,:D_226,:D_227,:D_228,:D_223,:D_224,:D_225,:D_220,:D_221,:D_222,:D_217,:D_218,:D_219,:D_214,:D_215,:D_216,:D_211,:D_212,:D_213,:D_208,:D_209,:D_210,:D_205,:D_206,:D_207,:D_202,:D_203,:D_204,:D_199,:D_200,:D_201,:D_196,:D_197,:D_198,:D_193,:D_194,:D_195,:D_190,:D_191,:D_192,:D_187,:D_188,:D_189,:D_184,:D_185,:D_186,:D_181,:D_182,:D_183,:D_178,:D_179,:D_180,:D_175,:D_176,:D_177,:D_172,:D_173,:D_174,:D_169,:D_170,:D_171,:D_166,:D_167,:D_168,:D_163,:D_164,:D_165,:D_160,:D_161,:D_162,:D_157,:D_158,:D_159,:D_154,:D_155,:D_156,:D_151,:D_152,:D_153,:D_148,:D_149,:D_150,:D_145,:D_146,:D_147,:D_142,:D_143,:D_144,:D_139,:D_140,:D_141,:D_136,:D_137,:D_138,:D_133,:D_134,:D_135,:D_130,:D_131,:D_132,:D_127,:D_128,:D_129,:D_124,:D_125,:D_126,:D_121,:D_122,:D_123,:D_118,:D_119,:D_120,:D_115,:D_116,:D_117,:D_112,:D_113,:D_114,:D_109,:D_110,:D_111,:D_106,:D_107,:D_108,:D_103,:D_104,:D_105,:D_100,:D_101,:D_102,:D_097,:D_098,:D_099,:D_094,:D_095,:D_096,:D_091,:D_092,:D_093,:D_088,:D_089,:D_090,:D_085,:D_086,:D_087,:D_082,:D_083,:D_084,:D_079,:D_080,:D_081,:D_076,:D_077,:D_078,:D_073,:D_074,:D_075,:D_070,:D_071,:D_072,:D_067,:D_068,:D_069,:D_064,:D_065,:D_066,:D_061,:D_062,:D_063,:D_058,:D_059,:D_060,:D_055,:D_056,:D_057,:D_052,:D_053,:D_054,:D_049,:D_050,:D_051,:D_046,:D_047,:D_048,:D_043,:D_044,:D_045,:D_040,:D_041,:D_042,:D_037,:D_038,:D_039,:D_034,:D_035,:D_036,:D_031,:D_032,:D_033,:D_028,:D_029,:D_030,:D_025,:D_026,:D_027,:D_022,:D_023,:D_024,:D_019,:D_020,:D_021,:D_016,:D_017,:D_018,:D_013,:D_014,:D_015,:D_010,:D_011,:D_012,:D_007,:D_008,:D_009,:D_004,:D_005,:D_006,:D_001,:D_002,:D_003,:PROTOKOLLNR,:GERAETENR,:PRUEFER,:UEBERTRAGUNGSDATEN,:ID_GERAET2,:ID_GERAET3,:ID_GERAET4,:GERAETENR2,:GERAETENR3,:GERAETENR4,:Bemerkungen,:Durchgefuehrte_Arbeiten,:ID_Techniker)";
try {
$db = DB::getInstance();
$stmt = $db->dbh->prepare($sql);
$stmt->bindParam(':ZEITSTEMPEL', $ZEITSTEMPEL); //this is also null??
$stmt->bindParam(':ID_MESSPROTOKOLL', $ID_MESSPROTOKOLL);
$stmt->bindParam(':ID_GERAET', $ID_GERAET);
//continues...
$stmt->execute();
$count = $stmt->rowCount();
$db = null;
$json = '{"count":{'.json_encode($count).'}}';
} catch(PDOException $e) {
return '{"error":{"text":'. $e->getMessage() .'}}';
}
return $json;
}
}
如果您需要示例 JSON,请告诉我。
任何想法?谢谢英格